PDA

View Full Version : Comparing numbers and booleans?



cchian
04-29-2004, 12:02 AM
This is the error message I am getting: "On Preload, Line 70: Attempt to compare number with string".

I am trying to work out the logic so an Update button is disabled if the program has never been installed. Also the Update button must be enabled if installed program has a lower version than the one on the CD.

Here is the relevant code I have so far:



version2 = 0000
version2 = INIFile.GetValue(mainpath.."\\myapp.ini", "program", "version");
appinstalled = File.DoesExist(mainpath.."\\MyApp.exe");
Button.SetEnabled("update", false);
if version1 > version2 and appinstalled then
Button.SetEnabled("update", true);
end


Note:
"mainpath" contains the path to the application, its value will be NIL in new installations because the program path is read from a local INI file when program is installed.

The error does not come up after first version of program is already installed.

Worm
04-29-2004, 04:49 AM
Even though the value of version in the ini file may be numeric, the action INIFile.GetValue returns a variable of type String. After your INIFile.GetValue statement, do this:

version2=String.ToNumber(version2)

That will force version2 to be numeric, then when you compare version1 and version2 (version1 > version2) you won't get the error.





This is the error message I am getting: "On Preload, Line 70: Attempt to compare number with string".

I am trying to work out the logic so an Update button is disabled if the program has never been installed. Also the Update button must be enabled if installed program has a lower version than the one on the CD.

Here is the relevant code I have so far:



version2 = 0000
version2 = INIFile.GetValue(mainpath.."\\myapp.ini", "program", "version");
appinstalled = File.DoesExist(mainpath.."\\MyApp.exe");
Button.SetEnabled("update", false);
if version1 > version2 and appinstalled then
Button.SetEnabled("update", true);
end


Note:
"mainpath" contains the path to the application, its value will be NIL in new installations because the program path is read from a local INI file when program is installed.

The error does not come up after first version of program is already installed.

cchian
04-29-2004, 10:27 PM
You are right, thank you!!!