trying to figure out a IF statement

# Thread: trying to figure out a IF statement

1. Senior Member
Join Date
Dec 1969
Posts
111

## trying to figure out a IF statement

I am running a Do While Not recordSet.EOF loop and need to convert it to a If statement. I first did the do while loop because the search can produce anywhere from 1 record or 100 records that are displayed in a table format. any ideas on how I can convert this over to the if statement?

2. Kentium Guest

## this work?

if not objRec.eof then<BR>do whatever<BR>end if

3. Senior Member
Join Date
Dec 1969
Posts
607

## RE: trying to figure out a IF statement

If not recordset.eof then<BR>&#039;do stuff<BR>else<BR>&#039;do other<BR>end if

4. Senior Member
Join Date
Dec 1969
Posts
1,431

## what are you talking about?

are you trying to break out of a loop or what? <BR><BR>An if statement is used to examine the one or more conditions if true then evaluate one or more statements in that if branch, else move to else or elseif branch etc<BR><BR>eg<BR><BR>If a=2 then<BR> b=4<BR>ElseIf a=3 then<BR> b=5<BR> c=6<BR>Else<BR> z=10<BR>End If<BR><BR>A doo while loop is used to execute a bunch of commands until the WHILE condition becomes false<BR><BR>eg<BR>i=0<BR>Do while i&#060;100 <BR> i=1+1<BR>Loop<BR><BR>will execute i=i+1 100 times until i is eventually = 100

5. Senior Member
Join Date
Dec 1969
Posts
607

## Kentium you have Pentium, beat me

by a full minute :)

6. Senior Member
Join Date
Dec 1969
Posts
111

## RE: what are you talking about?

I am running a do while to display all the results of a search in a table format until it hit EOF. I need to run the if statement to do the same thing but I need the if statement because I need to check for something else also.

7. Senior Member
Join Date
Dec 1969
Posts
1,431

## Then do

&nbsp;<BR><BR>Do while not rs.eof<BR> If someOtherCondition Then &#039;eg rs("field1") =2<BR> exit do<BR> Else<BR> &#039;do something<BR> End If<BR>Loop

8. Senior Member
Join Date
Dec 1969
Posts
111

## RE: Then do

I tried that an I never reach my my else in the if statment. This is what I have for code. I am running a database that keeps track of dies and I need to print a table that that show the results of the search. I also need to check for EOF and display a message if I reach the EOF without finding any match.<BR><BR>Do While Not recordSet.EOF<BR> if Not(recordSet.EOF) then<BR><BR> <BR> Response.Write("&#060;TR&#062;")<BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DIE #"))<BR> Response.Write("&#060;/TD&#062;")<BR> <BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DRAWING #"))<BR> Response.Write("&#060;/TD&#062;")<BR> <BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("SIZE"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DESCRIPTION"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("COMPANY"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("TYPE"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("PAD #"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DATE"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DRAWN BY"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("DISTRIBUTION"))<BR> Response.Write("&#060;/TD&#062;")<BR><BR> Response.Write("&#060;TD&#062;")<BR> Response.Write(recordSet("REVISION"))<BR> Response.Write("&#060;/TD&#062;")<BR> Response.Write("&nbsp")<BR> Response.Write("<BR>")<BR> Response.Write("&#060;/TR&#062;") <BR> &#039; recordSet.MoveNext<BR> else <BR> session("blnEOF") = true<BR> response.redirect("search.asp")<BR> <BR> end if <BR>loop<BR>

9. Senior Member
Join Date
Dec 1969
Posts
1,431

## That's not what I thought you were asking but

here&#039;s how you do it<BR><BR>If Not Rs.Eof Then<BR> Do while Not Rs.Eof<BR> &#039;some code<BR> Loop<BR>Else<BR> &#039;Some code<BR>End If

10. Senior Member
Join Date
Dec 1969
Posts
1,431

## RE: That's not what I thought you were asking

Also be sure to clean up the db variables before page ends or redirect somewhere else.

#### Posting Permissions

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