cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Happy_Days
Level 7

InstallScript - Real Number

Forgive me if this sounds stupid but I am not finding the answer. How do i compare a real number with another in InstallScript? I need to check if the version of an installed application is greater then 1.4...how do i do that!
If I declare a variable of type NUMBER, it coverts 1.4 to 1 :eek:
Labels (1)
0 Kudos
(6) Replies
RobertDickau
Flexera Alumni

There is no built-in non-integer numeric data type in InstallScript, but see for example VerCompare...
0 Kudos
Happy_Days
Level 7

Ah ok. Thats a limitation I think, is there any workaround?

I just tried VarCompare and it failed too...am i doing anything wrong here:

VerCompare("1.4", "1.1", VERSION) returns -1 !
0 Kudos
RobertDickau
Flexera Alumni

Perhaps try padding with zeros: "1.4.0.0" vs. "1.1.0.0"?
0 Kudos
Happy_Days
Level 7

There is no doubt, you are genius...it worked 🙂

But why it does not work with 1.2 and 1.4? The InstallScript Help says:

szVersionInfo1 : Specifies the first version string in the following format:

.

If szVersionInfo1 is 2.1.2.0, the major version number is 2.1 and the minor version number is 2.0.

szVersionInfo2 : Specifies the second version string in the same format.


So, ideally it should work with numbers like 1.1 and 1.4?
0 Kudos
RobertDickau
Flexera Alumni

I'm not sure why the documentation uses the terminology that it does (in a.b.c.d, calling a.b the major version and c.d the minor version), but it seems to want four-field versions...
0 Kudos
phill_mn
Level 7

What I do for situations like this is to get the version on the string format as indicated in the prior post, then tokenize it into separate strings, and then convert each string to a number as in the following code snippet.
#define _PRE_MSI_VER_MAJOR 3
#define _PRE_MSI_VER_MINOR 1

function BOOL MSIVersionCheck()
number nReturn, nMajor, nMinor;
BOOL bSelected;
string szPath, szVerNum, szMajor, szMinor;
LIST listID;
begin
bSelected = FALSE;
szPath = WINSYSDIR ^ "msi.dll";
nReturn = VerGetFileVersion(szPath, szVerNum);
if (nReturn = 0) then
listID = ListCreate(STRINGLIST);
if (StrGetTokens (listID, szVerNum, ".") > 0) then
// Report the error.
MessageBox ("StrGetTokens failed.", SEVERE);
else
/*Some call it Major.minor.build.revision
others call a file version (x.x.y.y) Major (x.x) and minor (y.y)*/
nReturn = ListGetFirstString (listID, szMajor);
if (nReturn != END_OF_LIST) then
nReturn = ListGetNextString (listID, szMinor);
endif;
nReturn = StrToNum(nMinor, szMinor);
nReturn = StrToNum(nMajor, szMajor);
if (nMajor < _PRE_MSI_VER_MAJOR) then
bSelected = TRUE;
endif;
if ((nMajor = _PRE_MSI_VER_MAJOR) &&
(nMinor < _PRE_MSI_VER_MINOR)) then
bSelected = TRUE;
endif;
endif;
// Remove the list from memory.
ListDestroy (listID);
endif;
return bSelected;
end;
0 Kudos