Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    47

    Question Unanswered: Convert string to condition

    Hi,

    I have the following code that doesnt work...

    Code:
    Public Sub temp()
    Dim strwhere, signs As String
    Dim num1, num2 As Single
    
    num1 = 1
    signs = ">"
    num2 = 2
    
    strwhere = num1 & signs & num2
    
    If strwhere Then
        MsgBox ("num1 is > num2")
    Else
        MsgBox ("num2 is > num1")
    End If
    End Sub
    The error I get is Type Mismatch in strwhere. I need the code to work this way 'cos num1, signs and num2 are stored as records in a condition table.

    Any help is appreciated!!!

    Rgds

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try the following:

    If signs = ">" Then
    MsgBox ("num1 is > num2")
    ElseIf signs = "<"
    MsgBox ("num2 is > num1")
    Else
    MsgBox ("num2 is = num1")
    End If


  3. #3
    Join Date
    Feb 2004
    Posts
    47

    How to convert a string (say '>') to an operator (>)

    Thanks for the reply, Hambakka....

    Just wondering... is there no function to convert string to an operator?

    It would make my life simple, if there is one...

    Rgds

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Sorry, there is no function to do that, but you can write it yourself.

  5. #5
    Join Date
    Feb 2004
    Posts
    47

    Question

    Can u help me with the code?

    Rgds,

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    PHP Code:
    Function String2Sign(thisString)
      
    Select Case UCase(thisString)
        Case 
    "LT"
         
    String2Sign "<"
        
        
    Case "LE"           ' Less than or equal
         String2Sign = "<="
        
        
        Case "GT"
         String2Sign = ">"
         
        Case "GE"       ' 
    Greater than or equal
         String2Sign 
    ">="
         
        
    Case "EQ"       ' Equal
         String2Sign = "="
         
        Case "NE"       ' 
    NOT Equal
         String2Sign 
    "<>"
         
       
    Case Else
         
    String2Sign ""
      
    End Select
    End 
    Function

    [/
    QUOTE

    Calling [COLOR=DarkOrchid]String2Sign("LT")[/COLOR]
    will result in '<' 

Posting Permissions

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