Problem, problem, problem

# Thread: Problem, problem, problem

1. Toni Guest

## Problem, problem, problem

Any idea why it only checks the 1st line of the "if" and gives the same response.write result?<BR>&#060;%<BR>If (Depth1 =&#060; 10 & Time1 =&#060; 60) then<BR>Response.Write("You are an A Diver Depth1 =&#060; 10 & Time1 =&#060; 60")<BR>else<BR>If (Depth1 =&#060;15 & Time1 =&#060; 35)then<BR>Response.Write("You are an A Diver - Depth1 =&#060;15 & Time1 =&#060; 35")<BR>else<BR>if (Depth1 =&#060; 20 & Time1 =&#060; 25) then<BR>Response.Write("You are an A Diver - Depth1 =&#060; 20 & Time =&#060; 25")<BR>else<BR>if (Depth1 =&#060; 25 & Time1 =&#060; 20) then<BR>Response.Write("You are an A Diver - Depth1 =&#060; 25 & Time =&#060; 20")<BR>else<BR>if (Depth1 =&#060; 30 & Time1 =&#060; 15) then<BR>Response.Write("You are an A Diver - Depth1 =&#060; 30 & Time =&#060; 15")<BR>else<BR>if (Depth1 =&#060; 35 & Time1 =&#060; 5) then<BR>Response.Write("You are an A Diver - Depth1 =&#060; 35 & Time =&#060; 5")<BR>else<BR>if (Depth1 =&#060; 40 & Time1 =&#060; 5) then<BR>Response.Write("You are a A Diver - Depth1 =&#060; 40 & Time =&#060; 5")<BR>else<BR>If (Depth1 =&#060; 40 & Time1 &#060; 19) then<BR>Response.Write "You are an A Diver"<BR>else<BR>if (Depth1 =&#060; 50 AND Time1 &#060;16) then<BR>Response.Write "You are a B Diver"<BR><BR>End if<BR>End if<BR>End if<BR>End if<BR>End if<BR>End if<BR>End if<BR>End if<BR>End if<BR><BR>%&#062;<BR>oh... and if you know an easier way (not involving SQL) it would make my life easier since there are about a hundred other if/then/else statements involved b4 this is finished...<BR><BR>Thank you

2. Senior Member
Join Date
Dec 1969
Posts
733

## RE: Problem, problem, problem

I&#039ll just give you the first few lines of this. I also love to dive (but I cheat and use a computer so I don&#039t have to consult the tables, except as a backup)...<BR><BR>&#060;%<BR>If (Depth1 =&#060; 10 And Time1 =&#060; 60) then<BR>Response.Write("You are an A Diver Depth1 =&#060; 10 & Time1 =&#060; 60")<BR>ElseIf (Depth1 =&#060;15 And Time1 =&#060; 35)then<BR>Response.Write("You are an A Diver - Depth1 =&#060;15 & Time1 =&#060; 35")<BR><BR>etc<BR><BR>End If &#039will only need one<BR>%&#062;<BR>

3. Sathiya Guest

## RE: Problem, problem, problem

If (Depth1 =&#060; 10 & Time1 =&#060; 60) then<BR><BR>is it VBScript or Javascript<BR><BR>use and or &&<BR>

4. Steve Cimino Guest

## RE: Problem, problem, problem

First of all, your values are not mutually exclusive, which, if you use this type of checking, you&#039ll need to change that (unless you want nested statements underneath).<BR><BR>Secondly, we need to get rid of all these ifs. Too many of them just gets too **** confusing to read. You should look at the docs for the If statement. Instead of If then else... and keep going, you can use ElseIf. Makes it easier to read, and you only need one End If.<BR><BR>Start at the highest possible number, and work your way down. In programming, once the condition evaluates to true (your first statement) it doesn&#039t continue checking the other statements; rather, it goes to it&#039s End If. So the rest of your code is useless if the first statement is true.<BR><BR>So<BR><BR>If depth &#062; 60 Then<BR>&#039Do depth greater than 60<BR>ElseIf depth &#062;50<BR>&#039Handles all the 50 ranges<BR>ElseIf depth &#062; 40<BR>&#039You get the idea?<BR>End If<BR><BR>Forget the Ands. If you do it this way, you&#039ll have what you want. Make the values mutually exclusive! If you can&#039t, start nesting statements underneath.

5. Steve Cimino Guest

## One correction

I stated in programming lanuages, that once it evaluates to true, it doesn&#039t continue to do so. I forgot about the C++ switch statment, where you have to force it out, or it will keep evaluating.<BR><BR>switch (value){<BR> case 1:<BR> case 2:<BR> //this line will handle both case 1 and 2<BR> break; //This is how you tell it to stop checking<BR>default:<BR>//no break statements? You&#039ll always get me<BR>}

6. Toni Guest

## RE: Problem, problem, problem

Thank you... I think I get the idea... two sets of code, but I am going to reuse one half later on anyway.. 2 problems solved!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•