|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
version comparison
okay. ive got to compare some versions of a program.
i have to a String, that is the version number i am comparing too, with the current verison of the program. the string is, say sNewVersionNo = "1.3.0" i know there are inbuilt functions in VB6 that can convert this is an integer withou the decimal points. so, i want it to become iNewVersionNo = 130 then i can make a seperate integer for the current version number: iCurrentVersionNo = (App.Major * 100) + (App.Minor * 10) + App.Revision then i only have to compare to two. ie If iNewVersionNo > iCurrentVersionNo then my question is, how do i make a string "1.3.0" become an integer 130? |
|
#2
|
||||
|
||||
|
This could be a round-about way to do it, but if you have
1.3.0... then you could do something like this... Code:
dim strTemp as string
dim strTempArray() as string
dim intFinal as integer
dim i as Integer
strtemp="1.3.0" 'Put your variable holding this value here
strTempArray() = Split("1.3.0", ".")
for i = 0 to UBound(strTempArray)
strTemp = strTemp & strTempArray(i)
next i
intfinal = cint(strTemp)
I'm fairly sure that there is a way to remove all occurences of a a string in another string, but I can't remember right now.. I'm stuck in Holiday Mode
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
Quote:
Hi,Fisherman!U give a good method,but i find a mistake which u didn't take care of:the assignment of strtemp variable. I modify your code as: dim strTemp as string dim strTempArray() as string dim strresult as string dim intFinal as integer dim i as Integer strtemp="1.3.0" 'Put your variable holding this value here strTempArray() = Split(strtemp, ".") strresult="" for i = 0 to UBound(strTempArray) strresult = strresult & strTempArray(i) next i intfinal = cint(strresult) ![]()
__________________
Being a Code Headman !
|
|
#4
|
||||
|
||||
|
No.. I didn't worry about the reassignment of the variable. I often reuse Temp variables because I don't want to allocate more memory space for an extra variable if it's only going to be used for a small amount of functionality
|
|
#5
|
|||
|
|||
|
Thanks guys, I used that example and it works like a charm now! I remember using the Split method now, so hopefully I'll remember it next time I need to use it!
Thanks again |
|
#6
|
||||
|
||||
|
glad to be of service
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > version comparison |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|