Results 1 to 14 of 14

Thread: [RESOLVED] [2005] compare strings

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    48

    Resolved [RESOLVED] [2005] compare strings

    I'm comparing 2 strings, they happen to be version numbers that have both numbers and letter(s) in the string, how can i tell if 123b is newer than 123a ?

  2. #2
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    I think you have to put every character in a variable and then compare al these variables with eachother.

  3. #3
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [2005] compare strings

    you could convert the letters into numbers, Asc("b") is a higher number than Asc("a")

  4. #4
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    yes you can do that. can you put every single char in a different variable.
    and than you have to compare. like 1 > 0

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    48

    Re: [2005] compare strings

    how would i pull the letters from the numbers?

  6. #6
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    wait a second. i have done that a time ago in another program. but I can't remember how to do that. I will look it up

  7. #7
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    first you have to know how many chars are in the textbox.
    Code:
            intamount = strversion1.Length

  8. #8
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    end then to get all single chars you have to use a for next structure. for the rest you maybe better ask another user that's more experienced

  9. #9
    Lively Member
    Join Date
    Nov 2007
    Location
    Doo Keep Doo !
    Posts
    108

    Re: [2005] compare strings

    Try this, i think this is not a flexible one but give it a try.

    Code:
    Dim chk As Integer
    Dim first As String, second As String
    Dim hld1 As String, hld2 As String
    
    first = Textbox1.Text
    second = Textbox2.Text
    
    For chk = 1 To 99
            hld1 = Mid$(first, chk, 1)
            hld2 = Mid$(second, chk, 1)
    
                 If Not hld1 = hld2 Then
                     MessageBox.Show("Not The Same")
                     Exit For
                 End If
    Next
    You can make some experiment of that

  10. #10
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [2005] compare strings

    yes lik this
    Code:
    Dim chk As Integer
    Dim first As String, second As String
    Dim hld1 As String, hld2 As String
    dim intamount1, intamount2 as integer
    
    first = Textbox1.Text
    second = Textbox2.Text
    
    intamount1 = first.length
    intamount2 = second.length
    
    For chk = 1 To intamount1 and intamount2
            hld1 = Mid$(first, chk, 1)
            hld2 = Mid$(second, chk, 1)
    
                 If Not hld1 = hld2 Then
                     MessageBox.Show("Not The Same")
                     Exit For
                 End If
    Next
    but from the "intamount1 and intamount2" I don't know for sure if it's that way to do. but you can certainly know how many chars are in that textbox then

  11. #11
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] compare strings

    Code:
        Private Sub CompareVersionNumbers(ByVal lhs As String, ByVal rhs As String)
            If lhs > rhs Then
                MessageBox.Show(lhs + " is newer than " + rhs)
            Else
                MessageBox.Show(rhs + " is newer than " + lhs)
            End If
        End Sub

  12. #12
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [2005] compare strings

    Quote Originally Posted by Fromethius
    Code:
        Private Sub CompareVersionNumbers(ByVal lhs As String, ByVal rhs As String)
            If lhs > rhs Then
                MessageBox.Show(lhs + " is newer than " + rhs)
            Else
                MessageBox.Show(rhs + " is newer than " + lhs)
            End If
        End Sub
    LOL he's right, it seems strings do have the > and < operators which work as you need it to.

  13. #13
    Addicted Member
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    154

    Re: [RESOLVED] [2005] compare strings

    nice, didn't think about that

  14. #14
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: [RESOLVED] [2005] compare strings

    How do we define lhs and rhs? With the string values from the TextBox?
    Code:
    lhs = TextBox1.Text
    rhs = TextBox2.Text

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