# Thread: Skipping in for loop

1. Registered User
Join Date
Nov 2008
Posts
117

## Unanswered: Skipping in for loop

My recordset contains datas as 11/2, 8/3 , 7 ,9

I am using FOR loop

I used coding in loop to convert them to decimals. But, what i want now is if there are no fractions in the recordset the data alone must be skipped.

(ie) it must convert to decimals for 11/2 and 8/3 but want to skip 7 and 9

Pls do anyone help me in this coding

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
what code are you using at present?

ID put a test inside the for loop using say the instr function

eg
if instr(mycolumn,"/") > 0 then
'do something to the fraction
else
'do something with the non fraction
endif

3. Registered User
Join Date
Nov 2008
Posts
117
Originally Posted by healdem
what code are you using at present?

ID put a test inside the for loop using say the instr function

eg
if instr(mycolumn,"/") > 0 then
'do something to the fraction
else
'do something with the non fraction
endif

I used the coding Below but not working.

Private Sub Command1_Click()
rs.Open "check1", db, 3, 2
If InStr(no1, "/") > 0 Then
a = Left([no1], InStr([no1], "/") - 1)
b = Right([no1], Len([no1]) - InStr([no1], "/"))
c = a / b
Call calc
Else
no1 = no1 / 1
Call calc
End If
rs.Close
End Sub

db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Bharani\Desktop\New Folder (2)\check.mdb;Persist Security Info=False"
End Sub

Private Sub calc()
rs.Open "check2", 3, 2
rs.Fields(0) = no1
rs.Update
rs.Close
End Sub

My output needs to be 5.5, 2.67, 7, 9
which must be added to database

4. Cavalier King Charles
Join Date
Dec 2002
Location
Préverenges, Switzerland
Posts
3,740
i'm sure you will agree that "not working" falls short of being a detailed technical explanation of the problem.

your first step should be to discover WHAT is not working.

a possible route: put a breakpoint on the line
If InStr(no1, "/") > 0 Then

when the code stops, Ctrl-G to open the immediate window. in the immediate window type
? no1 <return>
and see what happens.
once that does what you want, in the immediate window type:
? InStr(no1, "/") <return>
and then
? InStr(no1, "/") > 0 <return>
when happy, F8 and see if your code goes where you want it to go.
keep on hitting F8 and checking all the variables in the immediate window until it works.
? a <return>
? b <return>
? c <return>
etc etc etc etc etc
if you eventually get stuck, you will at least be able to explain WHAT is not working.

by the way - i don't see the For loop you mentioned in the original question.

izy

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•