cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DLee65
Level 13

VerCompare documentation is wrong

In IS2008 the VerCompare function documents that it WILL work with the format .. I just spent an hour or two trying to debug why this function was returning -1 when my version number is 1.65 and finally found my answer online. This has been an issue since before IS7!

I did notice that in the help file the line below this gives the example
"If szVersionInfo1 is 2.1.2.0, the major version number is 2.1 and the minor version number is 2.0." and in retrospect I can read the format into the syntax given above this line. However, the IF clause leads me to believe that this is not a requirement.

Can we get the function fixed or change the documentation so it is explicitly clear what is required. Thanks.
Labels (1)
0 Kudos
(2) Replies
DebbieL
Level 17

Ah, the VerCompare description and example in the documentation is very confusing. Sorry about that! We do have a KB article that clarifies how VerCompare works:
Q105636 - PRB: VerCompare Script Function Requires Version Parameters to be in a Specific Format

I created issue IOA-000043937 to fix the documentation. Thanks for reporting this!

Debbie Landers
Acresso Software
0 Kudos
TheTraveler
Level 8

I too found that the VerCompare is confusing as well. So I wrote my own. Here it is.
[CODE]///////////////////////////////////////////////////////////////////////////////
// P r o t o t y p e d F u n c t i o n s //
///////////////////////////////////////////////////////////////////////////////
EXTERNAL prototype My_CompareVersion(BYVAL string, BYVAL string);
EXTERNAL prototype My_AnalyzeVersion(BYVAL string, byref number, byref number, byref number, byref number);

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function My_AnalyzeVersion(strVersion, nMajor, nMinor, nRelease, nBuild)
STRING strTemp;
STRING strVal;
NUMBER nSize;
NUMBER nDotCount;
NUMBER nIndex;
CHAR cTemp;
begin
///////////////////////////////////////////////////////////////////////////
// I n i t i a l i z e V a r i a b l e s //
///////////////////////////////////////////////////////////////////////////
nMajor = 0;
nMinor = 0;
nRelease = 0;
nBuild = 0;

if StrLength(strVersion) > 0 then
///////////////////////////////////////////////////////////////////////
// I n i t i a l i z e V a r i a b l e s //
///////////////////////////////////////////////////////////////////////
strTemp = "";
nSize = 0;
nDotCount = 0;
nIndex = 0;

///////////////////////////////////////////////////////////////////////
// Loop through the version and break it down //
///////////////////////////////////////////////////////////////////////
nSize = StrLength(strVersion);
while ( nIndex < nSize )
cTemp = strVersion[nIndex];
if cTemp != "." then
Sprintf(strVal, "%c", cTemp);
strTemp = strTemp + strVal;
else
switch ( nDotCount )
case 0: StrToNum(nMajor, strTemp);
case 1: StrToNum(nMinor, strTemp);
case 2: StrToNum(nRelease, strTemp);
case 3: StrToNum(nBuild, strTemp);
endswitch;

strTemp = "";
nDotCount = nDotCount + 1;
endif;

nIndex = nIndex + 1;
endwhile;

///////////////////////////////////////////////////////////////////////
// Make sure I get the Last number
///////////////////////////////////////////////////////////////////////
if strTemp != "" then
switch ( nDotCount )
case 0: StrToNum(nMajor, strTemp);
case 1: StrToNum(nMinor, strTemp);
case 2: StrToNum(nRelease, strTemp);
case 3: StrToNum(nBuild, strTemp);
endswitch;
endif;
endif;
end;

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function My_CompareVersion(strVersion1, strVersion2)
NUMBER nResult;
NUMBER nMajor_v1;
NUMBER nMinor_v1;
NUMBER nRelease_v1;
NUMBER nBuild_v1;
NUMBER nMajor_v2;
NUMBER nMinor_v2;
NUMBER nRelease_v2;
NUMBER nBuild_v2;
begin
///////////////////////////////////////////////////////////////////////////
// I n i t i a l i z e //
///////////////////////////////////////////////////////////////////////////
nResult = -2;

My_AnalyzeVersion(strVersion1, nMajor_v1, nMinor_v1, nRelease_v1, nBuild_v1);
My_AnalyzeVersion(strVersion2, nMajor_v2, nMinor_v2, nRelease_v2, nBuild_v2);

if nMajor_v1 < nMajor_v2 then nResult = -1;
elseif nMajor_v1 > nMajor_v2 then nResult = 1;
elseif nMinor_v1 < nMinor_v2 then nResult = -1;
elseif nMinor_v1 > nMinor_v2 then nResult = 1;
elseif nRelease_v1 < nRelease_v2 then nResult = -1;
elseif nRelease_v1 > nRelease_v2 then nResult = 1;
elseif nBuild_v1 < nBuild_v2 then nResult = -1;
elseif nBuild_v1 > nBuild_v2 then nResult = 1;
else nResult = 0;
endif;

///////////////////////////////////////////////////////////////////////
// C o m p a r e t h e S t r i n g s //
///////////////////////////////////////////////////////////////////////
return nResult;
end;[/CODE]

My_AnalyzeVersion, Parses the version into its numeric parts. Easier to do numeric comparisons.

My_CompareVersion, This function calls the My_AnalyzeVersion to obtain the numberic values and then My_CompareVersion does the final comparing of each of the numeric portions in the version string.

Example:
nResult = My_CompareVersion(strInstalledVersion, IFX_PRODUCT_VERSION);

Return Results:
-2 == Unknown Error.
-1 == strVersion1 is an older version than strVersion2
0 == The two versions are identical.
1 == strVersion1 is a newer version than strVersion2
0 Kudos