Results 1 to 3 of 3

Thread: Can the expressions AND and OR go together in a IF statement in vbscript

  1. #1
    Guest
    Hi there, I'm trying to make a sub function accessible only if multiple conditions are met. If I only use multiple AND's or multiple OR's at once it works fine but when I try to combine them it won't work. I wonder if I'm using the correct syntax. This is what I tried:

    If (selected="Monday") And (id="A1" OR id="A2") then
    {do certain things}
    End If


    Looks like I can't use the brackets but how else can it be done? Please send your suggestions.
    Thank you for your time.

  2. #2
    Junior Member
    Join Date
    Aug 2000
    Location
    Rockford, IL
    Posts
    21

    Try something like this...

    Private Sub Command1_Click()
    Dim a
    Dim b
    Dim c

    a = "YES"
    b = "NO"
    c = "NO"

    If a = "YES" And b = "YES" Or c = "YES" Then
    MsgBox "Yup for A and maybe B or C"
    End If

    End Sub

    'I test this and it seemd to work okay

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Hardballa

    (I'm assuming you are using the VBScript in an Active Server Page)

    Your code looks ok to me!

    I just tried this and it was OK.

    Are you sure your values for selected, A1 and A2 are being set correctly?



    Code:
    <HTML>
    <HEAD>
    
    </HEAD>
    <BODY>
    <%
    dim selected
    dim id
    
    
    selected="Monday"
    'selected="Tuesday"
    'id="A2"
    id="A1"
    
    If (selected="Monday") And (id="A1" OR id="A2") then 
    response.write("conditions met")
    
    else
    response.write("conditions NOT met")
    End If 
    
    
    
    
    %>
    
    </form>
    </BODY>
    </HTML>
    Mark
    -------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width