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

ElseIf Question vs. Else on Final Condition Check

Status
Not open for further replies.

Coder7

Programmer
Oct 29, 2002
224
US
Good morning all! Thanks for any help and have a great day.

Here's the issue:

I have a Production problem with an asp page. I noticed that I used 'elseif' instead of 'else' for the two condition checks for "ElseIf sAuthCode = 4" and I was wondering if this could cause any logic problems.

<script>
If CStr(strCompanyInd) = "" Then
If sAuthCode = 1 Then
authNav = "H1"
ElseIf sAuthCode = 2 Then
authNav = "H2"
ElseIf sAuthCode = 3 Then
authNav = "H3"
ElseIf sAuthCode = 4 Then
authNav = "H4"
End If
Else
If sAuthCode = 1 Then
authNav = "E1"
ElseIf sAuthCode = 2 Then
authNav = "E2"
ElseIf sAuthCode = 3 Then
authNav = "E3"
ElseIf sAuthCode = 4 Then
authNav = "E4"
End If
End If
</script>
 
whats the problem?
the only one i see is this:
<script runat="server">



Known is handfull, Unknown is worldfull
 
vbkris is right. The logic should be fine but if that's supposed to be server-side script then it will never execute.
 
Thanks for the responses. The <script> and </script> tags surrounding my script snippet in the original post were just to tell you where the scripting was began and ended in the forum message - it's not like that on my asp page.

In the global.asa it is specified:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>

---------------

Well you answered my question then. The last elseif that should be else shouldn't cause a logic problem.




 
There shouldn't be a logic problem there, but I would generally prefer to add an Else to the statement anyways, even if it was simply outputting an error message or writing to a log file to indicate that an unknown condition somehow got into the code. Basically just a safety net in case something unpredictable occurs or if you later add another piece of code tat ties into this one but accidentally sends variables of the wrong type (string where your expecting numbers, etc) that type of thing.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
yeah, I heard something about coding conventions once upon a time [wink]

In agreement with all but more so with Tarwn in the Else being a standard that should catch all failed conditions. It is a standard and should be left intake

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
Thanks Tarwn and onpnt - point well taken and I'll add that to the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top