|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Convert Variant String to DoubleWhat am I missing here? (Code pasted below) 1) Set objInstaller = CreateObject("WindowsInstaller.Installer") 2) Version = objInstaller.Version 3) Wscript.Echo typename(Version) 4) WScript.Echo IsNumeric(Version) 5) Version = Cdbl(Version) 6) Wscript.Echo typename(Version) I'm writing a script to check if Windows Installer 3.1(or above) is installed on our systems. The variable 'Version' holds the data I need but it comes as a string. To verify that its a string, I added lines 3 & 4. Now I'm trying to change it to the double subtype on line 5 but I get the error message "Microsoft VBScript runtime error: Type mismatch: 'Cdbl'". Can someone please assist? I need to change it to double so I could perform an operation like: If Version > 3.1 Then (Do something) <remo0***@gmail.com> wrote in message
news:1141659071.842162.74870@u72g2000cwu.googlegroups.com... Since there's only 1 decimal point allowed, you're probably getting the > Hello, > > What am I missing here? (Code pasted below) error because the version string contains 3 decimals... '=========== Private Sub Command1_Click() Dim o As Object Set o = CreateObject("WindowsInstaller.Installer") Debug.Print o.version 'shows 3.1.4000.2435 'convert to number Dim v As Variant Dim d As Double v = o.version v = Split(v, ".") d = Val(v(0) & "." & v(1)) Debug.Print d 'shows 3.1 > If d > 3.1 Then (Do something) End Sub'=========== -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > 'convert to number Instead of the last two lines above, wouldn't this have worked as well?> Dim v As Variant > Dim d As Double > v = o.version > v = Split(v, ".") > d = Val(v(0) & "." & v(1)) d = Val(v) or, replacing all three lines and reducing it to a one-liner<g>, this d = Val(o.Version) Rick Show quoteHide quote > Debug.Print d 'shows 3.1 > > > If d > 3.1 Then (Do something) > > End Sub On my box, I get a string that looks like
3.1.4000.2435 which is why CDbl() fails. I think you will have to do some string manipulation to check the version, but I don't know enough about scripting to tell you how to approach it. <remo0***@gmail.com> wrote in message Show quoteHide quote news:1141659071.842162.74870@u72g2000cwu.googlegroups.com... > Hello, > > What am I missing here? (Code pasted below) > > 1) Set objInstaller = CreateObject("WindowsInstaller.Installer") > 2) Version = objInstaller.Version > 3) Wscript.Echo typename(Version) > 4) WScript.Echo IsNumeric(Version) > 5) Version = Cdbl(Version) > 6) Wscript.Echo typename(Version) > > I'm writing a script to check if Windows Installer 3.1(or above) is > installed on our systems. The variable 'Version' holds the data I need > but it comes as a string. To verify that its a string, I added lines 3 > & 4. Now I'm trying to change it to the double subtype on line 5 but I > get the error message "Microsoft VBScript runtime error: Type mismatch: > 'Cdbl'". Can someone please assist? I need to change it to double so I > could perform an operation like: > > If Version > 3.1 Then (Do something) > <remo0***@gmail.com> wrote
> I'm writing a script to check if Windows Installer 3.1(or above) is Why not just compare it as a string?> installed on our systems. The variable 'Version' holds the data I need > but it comes as a string. To verify that its a string, I added lines 3 > & 4. Now I'm trying to change it to the double subtype on line 5 but I > get the error message "Microsoft VBScript runtime error: Type mismatch: > 'Cdbl'". Can someone please assist? I need to change it to double so I > could perform an operation like: > > If Version > 3.1 Then (Do something) If Version >= "3.1" Then (Whatever) ??? LFS
About The Hard Disk Serial Number
Choosing an Installer Add an Item to a ListBox VB and Excel Crazy VB Calculate the Number of Subsets Find Path from VB Problem converting bytes array into string Acces Denied when calling FaxDocument Submit What considerations must be taken for app to run as a service? |
|||||||||||||||||||||||