Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Nested Loop/Conditional Statement :: Help Please
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  10:26:01  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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  Show Profile  Send ruirib a Yahoo! Message
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
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  11:09:42  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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
Go to Top of Page

es4725
Junior Member

205 Posts

Posted - 22 March 2002 :  11:14:44  Show Profile
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
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 March 2002 :  11:18:20  Show Profile  Send ruirib a Yahoo! Message
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
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  11:22:48  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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
Go to Top of Page

es4725
Junior Member

205 Posts

Posted - 22 March 2002 :  11:23:58  Show Profile
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)?

Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  11:28:06  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  11:33:39  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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
Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 22 March 2002 :  12:04:49  Show Profile  Visit Kat's Homepage
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/

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 March 2002 :  12:15:24  Show Profile  Send ruirib a Yahoo! Message
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
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 22 March 2002 :  12:33:35  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
No can do...Nothing happens. I give up...Anyone need a new Dell?

Jared Wuliger
jared@oxcyon.com
www.oxcyon.com
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 March 2002 :  12:42:55  Show Profile  Send ruirib a Yahoo! Message
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.34 seconds. Powered By: Snitz Forums 2000 Version 3.4.07