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 ?
Printable View
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 ?
I think you have to put every character in a variable and then compare al these variables with eachother.
you could convert the letters into numbers, Asc("b") is a higher number than Asc("a")
yes you can do that. can you put every single char in a different variable.
and than you have to compare. like 1 > 0
how would i pull the letters from the numbers?
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
first you have to know how many chars are in the textbox.Code:intamount = strversion1.Length
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
Try this, i think this is not a flexible one but give it a try.
You can make some experiment of thatCode: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
yes lik this
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 thenCode: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
:)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.Quote:
Originally Posted by Fromethius
nice, didn't think about that:)
How do we define lhs and rhs? With the string values from the TextBox?
:ehh: :confused:Code:lhs = TextBox1.Text
rhs = TextBox2.Text