Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

do while loop - it ALMOST works.

Status
Not open for further replies.

scroce

MIS
Nov 30, 2000
780
US
The following code is supposed to get employees from and employee table and sort them by department like so:

NO DEPARTMENT DEFINED:
fred jones
suzy smith
john doe

SALES:
john johnson
bobby brown
sid vicious

MARKETING
Joe joes
etc.
etc.


However there is a problem with the NO DEPARTMENT DEFINED part of the code. If, in the databse, the departmentID field is blank (isnull function), I want it to group under a single heading called NO DEPARTMENT DEFINED. But it is contiually coming out as:

NO DEPARTMENT DEFINED:
fred jones
NO DEPARTMENT DEFINED:
suzy smith
NO DEPARTMENT DEFINED:
john doe

SALES:
john johnson
bobby brown
sid vicious

MARKETING
Joe joes
etc.
etc.

Maybe I've been looking at this code for too long and have lost the ability to see what must be a fairly simple error in my loop. Can someone help me? Case 2 in the code below is where I believe the problem begins.


Do While rsEmployees.EOF = False
Select Case Session("GroupBy")
Case 0:

Case 1:
If LocationID <> rsEmployees(&quot;LocationID&quot;) Then
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD valign=top><font size=-1>&quot;)
Response.Write (&quot;  &quot;)
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD colspan=2 valign=top><font face=&quot;&quot;Arial, Helvetica, sans-serif&quot;&quot; size=2><B>&quot;)
Response.Write ( rsEmployees(&quot;Branch&quot;) & &quot;<BR> &quot; & rsEmployees(&quot;City&quot;) & &quot;, &quot; & rsEmployees(&quot;State&quot;))
Response.Write (&quot; </B></TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)
End If
LocationID = rsEmployees(&quot;LocationID&quot;)

Case 2:
If DepartmentID <> rsEmployees(&quot;DepartmentID&quot;) Then
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD valign=top><font size=-1>&quot;)
Response.Write (&quot;  &quot;)
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD colspan=2 valign=top><font face=&quot;&quot;Arial, Helvetica, sans-serif&quot;&quot; size=2><B>&quot;)
Response.Write ( rsEmployees(&quot;Department&quot;))
Response.Write (&quot; </B></TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)
else

End if
'Else
If isnull(rsEmployees(&quot;DepartmentID&quot;)) Then
'DepartmentID=&quot;No Department Defined&quot;
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD valign=top><font size=-1>&quot;)
Response.Write (&quot;  &quot;)
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)
Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD colspan=2 valign=top><font face=&quot;&quot;Arial, Helvetica, sans-serif&quot;&quot; size=2><B>&quot;)
Response.Write ( &quot;No Department Defined&quot;)
Response.Write (&quot; </B></TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)


' End If
' If rsEmployees(&quot;DepartmentID&quot;)=&quot;&quot; then
' DepartmentID = rsEmployees(&quot;DepartmentID&quot;)

else
departmentID=rsEmployees(&quot;DepartmentID&quot;)
end if
End Select

Response.Write (&quot; <TR>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; <TD valign=top><font face=&quot;&quot;Arial, Helvetica, sans-serif&quot;&quot; size=2>&quot;)
Response.Write (&quot; <a href=employee.asp?r=&quot; & Rand() & &quot;&EmployeeID=&quot; & rsEmployees(&quot;EmployeeID&quot;) & &quot;&command=Edit>&quot; & rsEmployees(&quot;Fullname&quot;) & &quot;</a>&quot;)
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; <TD><font face=&quot;&quot;Arial, Helvetica, sans-serif&quot;&quot; size=2>&quot;)
Response.Write ( rsEmployees(&quot;Priority&quot;))
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; <TD></TD>&quot;)
Response.Write (&quot; </TR>&quot;)

rsEmployees.MoveNext
Loop
Response.Write (&quot;</TABLE>&quot;)
Response.Write (&quot;</tr></td></table>&quot;)
Response.Write (&quot;</tr></td></table><p>&quot;) How much more water would there be in the ocean if it weren't for sponges?
 
It is in the loop. Every time RSEmployees(&quot;DepartmentID&quot;) is null, you write &quot;No dept. defined&quot;. Inside the loop you should check to see if depatmentID has changed. If it has, then check for isNull. One response if it is null another if it is not.
 
Deduced a solution for anyone who may be interested in troubleshooting do loops.

Solution was to implement a loopcounter, and then a statement saying that only if the loopcount < 1 to implement the code that writes the &quot;No Department Defined&quot; heading. How much more water would there be in the ocean if it weren't for sponges?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top