|
-
Nov 25th, 2007, 06:24 AM
#1
Thread Starter
Member
[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 ?
-
Nov 25th, 2007, 07:18 AM
#2
Addicted Member
Re: [2005] compare strings
I think you have to put every character in a variable and then compare al these variables with eachother.
-
Nov 25th, 2007, 07:24 AM
#3
Re: [2005] compare strings
you could convert the letters into numbers, Asc("b") is a higher number than Asc("a")
-
Nov 25th, 2007, 07:32 AM
#4
Addicted Member
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
-
Nov 25th, 2007, 07:33 AM
#5
Thread Starter
Member
Re: [2005] compare strings
how would i pull the letters from the numbers?
-
Nov 25th, 2007, 07:43 AM
#6
Addicted Member
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
-
Nov 25th, 2007, 08:01 AM
#7
Addicted Member
Re: [2005] compare strings
first you have to know how many chars are in the textbox.
Code:
intamount = strversion1.Length
-
Nov 25th, 2007, 08:22 AM
#8
Addicted Member
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
-
Nov 25th, 2007, 08:43 AM
#9
Lively Member
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
-
Nov 25th, 2007, 09:05 AM
#10
Addicted Member
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
-
Nov 25th, 2007, 09:54 AM
#11
Frenzied Member
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
-
Nov 25th, 2007, 12:21 PM
#12
Re: [2005] compare strings
 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.
-
Nov 27th, 2007, 04:38 PM
#13
Addicted Member
Re: [RESOLVED] [2005] compare strings
nice, didn't think about that
-
Nov 27th, 2007, 04:50 PM
#14
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|