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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested if else statement within another if else statement

Status
Not open for further replies.

ringadeal

Technical User
Jan 16, 2008
67
0
0
US
Does this asp code make sense as it is not giving error message but is not giving desired results

Secondly, there is a nested if else statement nested within another if else statement, must it be separated but some means?

Code:
<%
If Session("radius") <> "100" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) then
If Session("radius") <> "50" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) then
If Session("radius") <> "30" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) then
Session("radius")="30"
Response.Redirect("processform2.asp")
Else
Session("radius")="50"
Response.Redirect("processform2.asp")
End If
Else
Session("radius")="100"
Response.Redirect("processform2.asp")
End If
Else

'nested if else code
If Session("Industry")<>"" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) Then
If Session("VendorPartNumber")<>"" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) Then
If Session("PostalCode")<>"" AND (Recordset1.EOF Or Recordset1.BOF) AND (Recordset3.EOF Or Recordset3.BOF) Then
Session("PostalCode")= ""
Response.Redirect("processform2.asp")
Else
Session("VendorPartNumber")=""
Response.Redirect("processform2.asp")
End If
Else
Session("Industry")=""
Response.Redirect("processform2.asp")
End If
Else
Session("PostalCode")=""
Session("VendorPartNumber")=""
End If
'end of nested if else code

End If
%>
 
I'm having trouble figuring out your logic. You check to see if the radius is NOT 100, and if it's not check to see if it's NOT 50, then check to see if it's NOT 30. If it's NOT 30, you then set it to 30. If it's NOT 50, you set it to 50. Same for 100.

Can you not check to see if something DOES equal and do something accordingly, rather than all the nested if...else statements?

I'd recommend using CASE statements (if you have a finite number of options).
 
I'd recommend using CASE statements (if you have a finite number of options).

An even better recommendation would be to indent your code. Assuming you get the code to work correctly, it's gonna be a complete bitch to come back and modify later after you've forgotten what it's supposed to be doing. At least with proper indentation you can understand the nested flow at a glance.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top