Click to See Complete Forum and Search --> : print line within loop, but not after last item
jrthor2
03-30-2004, 03:27 PM
I have a script that lists events. I want to put a seperator image between each item, but not after the last item. Below is my code, cah someone tell me how to get it to not show my image seperator after the last item? I highlighted the code where I put the seperator in at:
Set RSEVENT = Server.CreateObject("ADODB.RecordSet")
RSEVENT.Open "SELECT * FROM Events ORDER BY Date", Conn, 1, 3
Do while NOT RSEVENT.EOF
'If mycolor = "#ffffff" Then
'mycolor = "#d7d7ff"
'Else
'mycolor = "#ffffff"
'End If
rsdate = RSEVENT("Date")
If (Day(rsdate) = Day(request("date"))) AND (Month(rsdate) = CInt(Month(request("date")))) AND (Year(rsdate) = CInt(Year(request("date")))) Then
eventEmpty = False
%>
<tr bgcolor="<%=mycolor%>">
<td colspan="3"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><b><%=FormatDateTime(rsdate, vbLongTime)%></b> <%=RSEVENT("Event_Name")%></font></td>
</tr>
<%
If (NOT isNull(RSEVENT("Location"))) Then
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Location</b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Location")%></font></td>
</tr>
<%End If%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Description </b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Description")%></font></td>
</tr>
<% if (NOT RSEVENT.EOF) then %>
<tr>
<td colspan="3" height="21" valign="center">
<div align="center"><img src="/images/purple_bar_menu.gif" width="100%" height="1"></div>
</td>
</tr>
<% Else
End If
End If
RSEVENT.movenext
Loop
RSEVENT.close
%>
buntine
03-30-2004, 07:24 PM
ok, the best way to get around thid is to use a For - next loop se we have a incrementing variable which we can check against the record count of the recordSet.
The following example may be helpful.
dim i
RSEVENT.MoveFirst
For i = 0 to RSEVENT.RecordCount
If not RSEVENT.EOF then
'|List event...
'|Show image if necessary.
if i < CInt(RSEVENT.RecordCount) then
'|Print image.
end if
RSEVENT.MoveNext
End If
Next
If this doesnt make sense, just ask me to show you in more detail.
Regards,
Andrew Buntine.
jrthor2
03-31-2004, 08:18 AM
If you could show me how in my current code to implement this, that would be great. I tried doing it, but it's not working out.
buntine
03-31-2004, 08:43 AM
Ok.
Set RSEVENT = Server.CreateObject("ADODB.RecordSet")
RSEVENT.Open "SELECT * FROM Events ORDER BY Date", Conn, 3
RSEVENT.MoveFirst
For i = 0 to RSEVENT.RecordCount
If not RSEVENT.EOF then
'If mycolor = "#ffffff" Then
'mycolor = "#d7d7ff"
'Else
'mycolor = "#ffffff"
'End If
rsdate = RSEVENT("Date")
If (Day(rsdate) = Day(request("date"))) AND (Month(rsdate) = CInt(Month(request("date")))) AND (Year(rsdate) = CInt(Year(request("date")))) Then
eventEmpty = False
%>
<tr bgcolor="<%=mycolor%>">
<td colspan="3">
<font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>">
<b><%=FormatDateTime(rsdate, vbLongTime)%></b> <%=RSEVENT("Event_Name")%>
</font>
</td>
</tr>
<%
If (NOT isNull(RSEVENT("Location"))) Then
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top">
<img src="/calendar/im/clear.gif" height="1" width="10">
</td>
<td valign="top">
<font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>">
<b>Location</b>
</font>
</td>
<td valign="top">
<font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>">
<%=RSEVENT("Location")%>
</font>
</td>
</tr>
<%End If%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top">
<font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>">
<b>Description </b>
</font>
</td>
<td valign="top">
<font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>">
<%=RSEVENT("Description")%>
</font>
</td>
</tr>
<% if i < CInt(RSEVENT.RecordCount) - 1 then %>
<tr>
<td colspan="3" height="21" valign="center">
<div align="center">
<img src="/images/purple_bar_menu.gif" width="100%" height="1">
</div>
</td>
</tr>
<% End If
End If
RSEVENT.movenext
end if
next
RSEVENT.close()
Set RSEVENT = Nothing
%>
Hows that?
Regards,
Andrew Buntine.
jrthor2
03-31-2004, 08:48 AM
that still gives me the line after the last item...
<%
dim i
eventEmpty = True
mycolor = "#ffffff"
Set RSEVENT = Server.CreateObject("ADODB.RecordSet")
RSEVENT.Open "SELECT * FROM Events ORDER BY Date", Conn, 1, 3
RSEVENT.MoveFirst
For i = 0 to RSEVENT.RecordCount
If not RSEVENT.EOF then
'If mycolor = "#ffffff" Then
'mycolor = "#d7d7ff"
'Else
'mycolor = "#ffffff"
'End If
rsdate = RSEVENT("Date")
If (Day(rsdate) = Day(request("date"))) AND (Month(rsdate) = CInt(Month(request("date")))) AND (Year(rsdate) = CInt(Year(request("date")))) Then
eventEmpty = False
%>
<tr bgcolor="<%=mycolor%>">
<td colspan="3"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><b><%=FormatDateTime(rsdate, vbLongTime)%></b> <%=RSEVENT("Event_Name")%></font></td>
</tr>
<%
If (NOT isNull(RSEVENT("Location"))) Then
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Location</b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Location")%></font></td>
</tr>
<%End If%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Description </b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Description")%></font></td>
</tr>
<% if i < CInt(RSEVENT.RecordCount) then %>
<tr>
<td colspan="3" height="21" valign="center">
<div align="center"><img src="/images/purple_bar_menu.gif" width="100%" height="1"></div>
</td>
</tr>
<%
End If
End If
RSEVENT.movenext
end if
next
RSEVENT.close()
Set RSEVENT = Nothing
%>
buntine
03-31-2004, 08:49 AM
Thats cause your not using the code i posted.. Look at the if statement again and see whats different between mine and yours.
Regards.
jrthor2
03-31-2004, 08:55 AM
sorry, cut from the wrong post, but it still gives me the line:
<%
dim i
eventEmpty = True
mycolor = "#ffffff"
Set RSEVENT = Server.CreateObject("ADODB.RecordSet")
RSEVENT.Open "SELECT * FROM Events ORDER BY Date", Conn, 1, 3
RSEVENT.MoveFirst
For i = 0 to RSEVENT.RecordCount
If not RSEVENT.EOF then
'If mycolor = "#ffffff" Then
'mycolor = "#d7d7ff"
'Else
'mycolor = "#ffffff"
'End If
rsdate = RSEVENT("Date")
If (Day(rsdate) = Day(request("date"))) AND (Month(rsdate) = CInt(Month(request("date")))) AND (Year(rsdate) = CInt(Year(request("date")))) Then
eventEmpty = False
%>
<tr bgcolor="<%=mycolor%>">
<td colspan="3"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><b><%=FormatDateTime(rsdate, vbLongTime)%></b> <%=RSEVENT("Event_Name")%></font></td>
</tr>
<%
If (NOT isNull(RSEVENT("Location"))) Then
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Location</b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Location")%></font></td>
</tr>
<%End If%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Description </b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Description")%></font></td>
</tr>
<% if i < CInt(RSEVENT.RecordCount) -1 then %>
<tr>
<td colspan="3" height="21" valign="center">
<div align="center"><img src="/images/purple_bar_menu.gif" width="100%" height="1"></div>
</td>
</tr>
<%
End If
End If
RSEVENT.movenext
end if
next
RSEVENT.close()
Set RSEVENT = Nothing
%>
buntine
03-31-2004, 09:00 AM
Your still not using the code i wrote.. Your connection parameters vary. You should use 3 apposed to 1, 3.
Try again and see what happens.
Regards.
jrthor2
03-31-2004, 09:05 AM
nope, same results:
<%
dim i
eventEmpty = True
mycolor = "#ffffff"
Set RSEVENT = Server.CreateObject("ADODB.RecordSet")
RSEVENT.Open "SELECT * FROM Events ORDER BY Date", Conn, 3
RSEVENT.MoveFirst
For i = 0 to RSEVENT.RecordCount
If not RSEVENT.EOF then
'If mycolor = "#ffffff" Then
'mycolor = "#d7d7ff"
'Else
'mycolor = "#ffffff"
'End If
rsdate = RSEVENT("Date")
If (Day(rsdate) = Day(request("date"))) AND (Month(rsdate) = CInt(Month(request("date")))) AND (Year(rsdate) = CInt(Year(request("date")))) Then
eventEmpty = False
%>
<tr bgcolor="<%=mycolor%>">
<td colspan="3"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><b><%=FormatDateTime(rsdate, vbLongTime)%></b> <%=RSEVENT("Event_Name")%></font></td>
</tr>
<%
If (NOT isNull(RSEVENT("Location"))) Then
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Location</b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Location")%></font></td>
</tr>
<%End If%>
<tr bgcolor="<%=mycolor%>">
<td valign="top"><img src="/calendar/im/clear.gif" height="1" width="10"></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=RSBODY("Link_Color")%>"><b>Description </b></font></td>
<td valign="top"><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>"><%=RSEVENT("Description")%></font></td>
</tr>
<% if i < CInt(RSEVENT.RecordCount) -1 then %>
<tr>
<td colspan="3" height="21" valign="center">
<div align="center"><img src="/images/purple_bar_menu.gif" width="100%" height="1"></div>
</td>
</tr>
<%
End If
End If
RSEVENT.movenext
end if
next
RSEVENT.close()
Set RSEVENT = Nothing
%>
buntine
03-31-2004, 09:09 AM
Employ some debugging techniques like printing the value of i and RSEVENT.recordCount.
You will have to play with it.