String comparison instead of numeric

Got a problem you cannot solve? Try here.
Post Reply
octavio
Posts: 6
Joined: Sun Aug 17, 2008 12:45 pm

String comparison instead of numeric

Post by octavio »

Hi,

I have a chunk of script which ckecks whether there are 4 GB available on target drive:

Set Variable TARGETDRIVE to $TARGETDIR$
Extract Parent Drive: TARGETDRIVE
Set Variable FREE_SPACE to 0
Get Free Space on $TARGETDRIVE$ into variable FREE_SPACE
if Variable FREE_SPACE not Greater Than 4000000000
MessageBox: $TITLE$ Setup Error, This installation requires at least 4 GB of available disk space in $TARGETDRIVE$. Please, free some disk space and run the installation again.$NEWLINE$$NEWLINE$Setup cannot continue.
Terminate Installation
end

The available free space is obtained ok, but when the comparison is performed, it is a STRING comparison and not a NUMERIC one, although both variables contain numbers (the help says in this case a numeric comparison is performed). So if the drive contains only 41 bytes free, the script passes the test because '41' is lexicographically after '4000000000'.

What to do?
octavio
Posts: 6
Joined: Sun Aug 17, 2008 12:45 pm

Post by octavio »

Solved, using "Mathematics":

Get Free Space on $TARGETDRIVE$ into variable FREE_SPACE
ENOUGH_SPACE = $FREE_SPACE$ / 4000000000
if Variable ENOUGH_SPACE Equals 0
MessageBox: $TITLE$ Setup Error, This installation requires at least 4 GB of available disk space in $TARGETDRIVE$. Please, free some disk space and run the installation again.$NEWLINE$$NEWLINE$Setup cannot continue.
Terminate Installation
end
Post Reply