Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

nested if else statement within another if else statement

ringadeal (TechnicalUser)
13 Feb 08 18:01
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
%>
mcpeekj (Vendor)
14 Feb 08 17:27
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).
kaht (Programmer)
14 Feb 08 17:32

Quote:

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

<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>

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close