Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Nested If Question

Reply
Thread Tools

Nested If Question

 
 
Dthmtlgod
Guest
Posts: n/a
 
      02-16-2005
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


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-16-2005
Dthmtlgod wrote:
> 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
--
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.


 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      02-16-2005
"Bob Barrows [MVP]" <> wrote in message
news:#...
> Dthmtlgod wrote:
> > 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
> --
> 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.)


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      02-16-2005
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


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      02-16-2005
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

--
dlbjr
Pleading sagacious indoctrination!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested friend class in nested template problem tonvandenheuvel@gmail.com C++ 3 12-07-2007 03:02 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Is nested class automatically friend of class that it is nested in? request@no_spam.com C++ 5 09-25-2006 08:31 AM
Nested Vector Nester Classes are Nested in my Brain Chad E. Dollins C++ 3 11-08-2005 04:46 AM
Nested iterators (well, not nested exactly...) Russ Perry Jr Java 2 08-20-2004 06:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57