Nested If Question

D

Dthmtlgod

Could someone please look at my code below, I am trying to nest a couple of
if statements together and it is not working. I think I am close.

if len(rsMove("MonitorID1")) > 0 and len(rsMove("MonitorID2")) > 0 then
response.write ("Dual Monitors")
else if len(rsMove("MonitorID1")) > 1 and len(rsMove("MonitorID2")) = 0 then
response.write ("Single Monitor")
else
response.write ("No Monitor")
end if
 
B

Bob Barrows [MVP]

Dthmtlgod said:
Could someone please look at my code below, I am trying to nest a

not really nested
couple of if statements together and it is not working. I think I am
close.

if len(rsMove("MonitorID1")) > 0 and len(rsMove("MonitorID2")) > 0
then response.write ("Dual Monitors")
else if

should be a single word: elseif

This would be nested:

if len(rsMove("MonitorID1")) > 0 and len(rsMove("MonitorID2")) > 0 then
response.write ("Dual Monitors")
else
if len(rsMove("MonitorID1")) > 1 and len(rsMove("MonitorID2")) = 0 then
response.write ("Single Monitor")
else
response.write ("No Monitor")
end if
end if

Bob Barrows
 
M

McKirahan

Bob Barrows said:
not really nested


should be a single word: elseif

This would be nested:

if len(rsMove("MonitorID1")) > 0 and len(rsMove("MonitorID2")) > 0 then
response.write ("Dual Monitors")
else
if len(rsMove("MonitorID1")) > 1 and len(rsMove("MonitorID2")) = 0 then
response.write ("Single Monitor")
else
response.write ("No Monitor")
end if
end if

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

This version might make it more readable.

It uses the line continuation character: "_".

If Len(rsMove("MonitorID1")) > 0 _
And Len(rsMove("MonitorID2")) > 0 Then
Response.Write ("Dual Monitors")
Else
If Len(rsMove("MonitorID1")) > 1 _
And Len(rsMove("MonitorID2")) = 0 Then
Response.Write ("Single Monitor")
Else
Response.Write ("No Monitor")
End If
End If


(I like capitalizing the first letter of keywords.)
 
E

Evertjan.

McKirahan wrote on 16 feb 2005 in
microsoft.public.inetserver.asp.general:
This version might make it more readable.

It uses the line continuation character: "_".

If Len(rsMove("MonitorID1")) > 0 _
And Len(rsMove("MonitorID2")) > 0 Then
Response.Write ("Dual Monitors")
Else
If Len(rsMove("MonitorID1")) > 1 _
And Len(rsMove("MonitorID2")) = 0 Then
Response.Write ("Single Monitor")
Else
Response.Write ("No Monitor")
End If
End If

Talking about readability and errorproneness:

D1 = Len(rsMove("MonitorID1"))
D2 = Len(rsMove("MonitorID2"))

If D1 > 0 And D2 > 0 Then
r = "Dual Monitors"
ElseIf D1 > 1 And D2 = 0 Then
r = "Single Monitor"
Else
r = "No Monitor"
End If

Response.Write r

====================

Then you immediately would see that
D1 > 1
most probably would need to be
D1 > 0

and that the case of
D1 = 0 And D2 > 0
would erroneously return "No Monitor"

====================

so this would probably be best:

====================

D1 = Len(rsMove("MonitorID1"))
D2 = Len(rsMove("MonitorID2"))

If D1 > 0 And D2 > 0 Then
r = "Dual Monitors"
ElseIf D1 > 0 Or D2 > 0 Then
r = "Single Monitor"
Else ' meaning: D1 = 0 And D2 = 0
r = "No Monitor"
End If

Response.Write r
 
D

dlbjr

Function GetMonitorCount(str1,str2)
GetMonitorCount = "No Monitor"
intL1 = Len(Trim(str1))
intL2 = intL1 + Len(Trim(str2))
If intL1 > 0 Then
GetMonitorCount = "Single Monitor"
If intL2 > intL1 Then
GetMonitorCount = "Dual Monitor"
End If
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top