Nested If Question

Discussion in 'ASP General' started by Dthmtlgod, Feb 16, 2005.

  1. Dthmtlgod

    Dthmtlgod Guest

    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
    Dthmtlgod, Feb 16, 2005
    #1
    1. Advertising

  2. 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.
    Bob Barrows [MVP], Feb 16, 2005
    #2
    1. Advertising

  3. Dthmtlgod

    McKirahan Guest

    "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.)
    McKirahan, Feb 16, 2005
    #3
  4. Dthmtlgod

    Evertjan. Guest

    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)
    Evertjan., Feb 16, 2005
    #4
  5. Dthmtlgod

    dlbjr Guest

    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!
    dlbjr, Feb 16, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ Perry Jr
    Replies:
    2
    Views:
    4,095
    Russ Perry Jr
    Aug 20, 2004
  2. Chad E. Dollins
    Replies:
    3
    Views:
    645
    Kai-Uwe Bux
    Nov 8, 2005
  3. request@no_spam.com
    Replies:
    5
    Views:
    411
  4. Ultrus
    Replies:
    3
    Views:
    361
    Stefan Behnel
    Jul 9, 2007
  5. Replies:
    3
    Views:
    456
    Victor Bazarov
    Dec 7, 2007
Loading...

Share This Page