SIMIN Posted August 2, 2008 Posted August 2, 2008 Hello, I want to compare 2 numbers in VB6. The numbers are in a format like: 1.2.3 So here 1.2.3 is less than 1.2.4. Also 1.2.3 is greater than 1.2.1. And 1.2.3 equals 1.2.3. So how should I do it? Dim NumberOne As Single Dim NumberTwo As Single NumberOne = 1.2.3 NumberTwo = 3.2.1 If Version > MyVersion Then ... End If If Version = MyVersion Then ... End If If Version < MyVersion Then ... End If But I think it has some logical problems as it won't compare correctly! Thank you for any ideas you might have! Quote
Administrators PlausiblyDamp Posted August 2, 2008 Administrators Posted August 2, 2008 The two decimal points would prevent the numbers being stored as a single, double or decimal. You might find the easiest way is to split the strings by the "." character and then convert each of the sections into an integer similar to the following... Dim NumberOne As String Dim NumberTwo As String NumberOne = "1.2.3" NumberTwo = "3.2.1" Dim nums1() As String nums1 = Split(NumberOne, ".") Dim nums2() As String nums2 = Split(NumberTwo, ".") Dim v1 As Integer Dim v2 As Integer Dim i As Integer For i = 0 To Len(nums1) v1 = CInt(nums1(i)) v2 = CInt(nums2(i)) If v1 > v2 Then 'v1 is biggest ElseIf v2 > v1 Then 'v2 is biggest End If Next 'both are same That might not be exact as I don't have vb6 on this pc so it is a bit from memory. It might be easier still though if you created either a class or a type to hold the version information as three separate integers and have a function that would compare the these types. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.