Author |
Topic |
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 10:26:01
|
I need some help with a conditional statement in a nested loop.
I am trying to show "None Avaliable" if there is no data to be displayed. Simple right? I have done that a million times. Now when I apply my conditional statement to the field in the nested loop, it prints "None Avaliable" if there is data or not.
Code Example:
Response.Write("<FONT face=Verdana, Arial, Helvetica, sans-serif size=1>") iCount = 0 While (NOT oProducts.EOF) If iCount > 1 Then Response.Write("; ") End If If Trim(oProducts.Fields.Item("Pc_prd_cd").Value) <> "" Then Response.Write("<A href=""/execute.asp?Section=BG&Sub=Results&ProdID=" & Trim(oProducts.Fields.Item("Pc_prd_cd").Value) & """ class=type2links>" & Trim(oProducts.Fields.Item("Pc_Descrip").Value) & "</A>") Else Response.Write("None Avaliable") End If iCount = iCount + 1 oProducts.MoveNext Wend Response.Write("</FONT>")
The Result:
(If There is data): Product Codes: None AvaliableHose, Compressed Air; Quality Engineer Supplies
(If There is no data): Product Codes: None Avaliable
What I dont get is that if I take out the conditional statement, if there is no data nothing will show up, not even emnty spaces. So I know for a fact there are records with emty fields.
I hope this makes sense.
Thanks!!!
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 22 March 2002 : 10:55:39
|
I'm not sure that I understood you. What were you expecting? Empty means empty as in nothing to show ...
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 11:09:42
|
Well, with my conditional statement turned on. As my code example shows, No matter if there is data in the field "Pc_prd_cd" or not. "None Avaliable" shows up on my page if there is data or not.
Does that help?
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
es4725
Junior Member
205 Posts |
Posted - 22 March 2002 : 11:14:44
|
Is there a record before hose that is empty? I don't see what else would cause it.
and should this: If iCount > 1 Then
not be this If iCount >= 1 Then
*edit* try changing that line, and see if you get "; " after None Available */edit*
Edited by - es4725 on 22 March 2002 11:17:03 |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 22 March 2002 : 11:18:20
|
I'm still not sure I got you.
Anyway here goes a suggestion. I've had problems before when comparing strings using relational operators. Using strComp for string comparison works better.
You can also try checking for zero lenght:
If Len(Trim(oProducts.Fields.Item("Pc_prd_cd").Value)) <> 0 ...
------------------------------------------------- Installation Guide | Do's and Dont's | MODs
Edited by - ruirib on 22 March 2002 11:18:56 |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 11:22:48
|
I double checked to make sure there wasn't an empty record before Hose, and there isn't. Also changing my code to:
If iCount >= 1 Then
diddn't work
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
es4725
Junior Member
205 Posts |
Posted - 22 March 2002 : 11:23:58
|
quote:
I double checked to make sure there wasn't an empty record before Hose, and there isn't. Also changing my code to:
If iCount >= 1 Then
diddn't work
no ; after none available (w/ other records)?
|
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 11:28:06
|
quote:
no ; after none available (w/ other records)?
Nope, ; doesn't show up around none available at all.
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 11:33:39
|
Wait. I diddn't see it at first, but yes there are empty records before Hose. How do I eliminate empty records from:
Response.Write("<A href=""/execute.asp?Section=BG&Sub=Results&ProdID=" & Trim(oProducts.Fields.Item("Pc_prd_cd").Value) & """ class=type2links>" & Trim(oProducts.Fields.Item("Pc_Descrip").Value) & "</A>")
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
Kat
Advanced Member
United Kingdom
3065 Posts |
Posted - 22 March 2002 : 12:04:49
|
Use If Len(Trim(oProducts.Fields.Item("Pc_prd_cd").Value)) <> 0 around your response.write statement as rui suggested.
Response.Write("<FONT face=Verdana, Arial, Helvetica, sans-serif size=1>")iCount = 0 While (NOT oProducts.EOF) If Len(Trim(oProducts.Fields.Item("Pc_prd_cd").Value)) <> 0 If iCount > 1 Then Response.Write("; ") End If If Trim(oProducts.Fields.Item("Pc_prd_cd").Value) <> "" Then Response.Write("<A href=""/execute.asp?Section=BG&Sub=Results&ProdID=" & Trim(oProducts.Fields.Item("Pc_prd_cd").Value) & """ class=type2links>" & Trim(oProducts.Fields.Item("Pc_Descrip").Value) & "</A>") Else Response.Write("None Avaliable") End If iCount = iCount + 1 End If oProducts.MoveNext Wend Response.Write("</FONT>")
You may just need to change where it checks for the empty record depending on what you need to output and increment at certain points.
KatsKorner
For Installation help: http://www.aslickpage.com/snitz_help.html For Snitz Mods: http://ls3k.com/snitz/
|
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 22 March 2002 : 12:15:24
|
Kat, you forgot the Then at the end of the line for the first If
Response.Write("<FONT face=Verdana, Arial, Helvetica, sans-serif size=1>")iCount = 0 While (NOT oProducts.EOF) If Len(Trim(oProducts.Fields.Item("Pc_prd_cd").Value)) <> 0 Then If iCount > 1 Then Response.Write("; ") End If If Trim(oProducts.Fields.Item("Pc_prd_cd").Value) <> "" Then Response.Write("<A href=""/execute.asp?Section=BG&Sub=Results&ProdID=" & Trim(oProducts.Fields.Item("Pc_prd_cd").Value) & """ class=type2links>" & Trim(oProducts.Fields.Item("Pc_Descrip").Value) & "</A>") Else Response.Write("None Avaliable") End If iCount = iCount + 1 End If oProducts.MoveNext Wend Response.Write("</FONT>")
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 22 March 2002 : 12:33:35
|
No can do...Nothing happens. I give up...Anyone need a new Dell?
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 22 March 2002 : 12:42:55
|
Try this:
Response.Write("<FONT face=Verdana, Arial, Helvetica, sans-serif size=1>")iCount = 0 While (NOT oProducts.EOF) If Len(Trim(oProducts.Fields.Item("Pc_prd_cd").Value)) <> 0 Then If iCount > 1 Then Response.Write("; ") End If Response.Write("<A href=""/execute.asp?Section=BG&Sub=Results&ProdID=" & Trim(oProducts.Fields.Item("Pc_prd_cd").Value) & """ class=type2links>" & Trim(oProducts.Fields.Item("Pc_Descrip").Value) & "</A>")
iCount = iCount + 1 Else Response.Write("None Avaliable") End If oProducts.MoveNext Wend Response.Write("</FONT>")
------------------------------------------------- Installation Guide | Do's and Dont's | MODs
Edited by - ruirib on 22 March 2002 12:44:59 |
|
|
|
Topic |
|