how to put several long IF statements together?

Discussion in 'C#' started by JJnacy, May 9, 2009.

  1. #1
    example:
    strQ= "q1=1 or q2=2 or q3=4 .............q10 or"

    If q11=11 or q12=12 or q13=14 .............q20=20 then
    answer="happy"
    end if

    I want to have from q1=1 to q=20 as query

    My question is:
    how do we put strQ into the "if then" statement?

    If [ strQ ] q11=11 or q12=12 or q13=14 .............q20=20 then
    answer="happy"
    end if

    Thanks/ Reqards
     
    JJnacy, May 9, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    This is a long way to do things.
    Try using an array:
    
    Dim q(20)
    For i = 1 to 20
         If q(i) = i Then answer="happy"
    Next
    
    Code (markup):
    But if what you mean is to evaluate a string like:
    
    strQ = "q1=1 or q2=2"
    If strQ Then
    answer="happy"
    End If
    
    Code (markup):
    then I don't think that this can be done in ASP.
     
    camjohnson95, May 11, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Sorry, yes it can.
    
    <%
    Dim strQ, q1, q2
    q1 = 1
    q2 = 5
    strQ = "q1 = 1 OR q2 = 2"
    
    If Eval(strQ) Then
    	Response.Write "happy"
    End If
    %>
    
    Code (markup):
     
    camjohnson95, May 11, 2009 IP
  4. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry, what I mean is:

    strQ= "q1=str1 or q2=str2 or q3=str4 .............q10=str10 or"

    If q11=str11 or q12=str12 or q13=str14 .............q20=str20 then
    answer="happy"
    end if

    I want to have from q1=str1 to q=str20 as query

    My question is:
    how do we put strQ into the "if then" statement?

    If [ strQ ] q11=str11 or q12=str12 or q13=str14 .............q20=str20 then
    answer="happy"
    end if

    I tried
    If & strQ & q11=str11 or q12=str12 or q13=str14 .............q20=str20 then
    but it was not working


    Thanks/ Reqards
     
    JJnacy, May 11, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    use:
    
    If Eval(strq) [B]OR[/B] q11=str11 or q12=str12 .......... then
    
    Code (markup):
    But strq shouldn't end with OR it should just be:
    strQ= "q1=str1 or q2=str2 or q3=str4 .............q10=str10"
     
    camjohnson95, May 11, 2009 IP
  6. web-bod

    web-bod Guest

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I still don't fully understand, but have you thought of using split(strq,"or") to give an array, and then working with that.
     
    web-bod, May 12, 2009 IP
    JJnacy likes this.
  7. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I still stay with array
     
    JJnacy, May 13, 2009 IP