PDA

View Full Version : Compare 2 Numbers



NewsArchive
01-19-2013, 03:00 AM
SB 7.7.3805
I have a problem with comparing 2 numbers.
The first number is extracted from a text file and formatted using
Handle String Function.
The result is 74,590,097,776. This is the uncompressed size of 8 files
in a .zip file.
The second number is returned from the Get System Info function, Free
Disk Space option.
The computer has 1.3 TB of free space so the second number now is
1386897334 which is not accurate so I multiple it by 1000 and format the
result using Handle String Function again.
The result is 1,386,891,334,000.
I then issue an IF check: IF Number 2(free space) is less than or equal
to Number 1 (size of uncompressed files).
It takes the true path and say that you do not have enough free space to
extract the zip file, which is false. I have plenty of free space.
If I change the IF to be IF Number 1(size of uncompressed files) is
greater than number 2 (free space), I get the true message.
Again this is wrong, free space is 1.3 TB and size if uncompress files
is 74 GB. How do I check these 2 numbers so I know I have enough free
space to extract my files?

Dee


--
Darrel (Dee) Witham
Professional Data Services, Inc

NewsArchive
01-19-2013, 03:00 AM
Dee,

Two things that you have to do:

1. To compare "numbers" from a formated string, you have to remove the ','
to convert the string into a number. For example: 74,590,097,776 =
74590097776 and 1,386,891,334,000 = 1386891334000. The "Handle String
Operation (Replace)" function can do this for you.

2. In SB7, you are limited to 32-bit values in conditional IF statements.
So you have to convert the Bytes value into, say, a KBytes value.

Similar to the attached screenshot.

BTW, in SB80, it will be possible to support 64-bit integer values in
conditional IF statements. But this can't help you at the moment.

Friedrich

NewsArchive
01-19-2013, 03:02 AM
See attached screenshots. The same project compiled with SB7 and SB8.

SB7 doesn't support 64-bit values in "If" Statement (Less Than, Less Than or
Equal, Greater Than and Greater Than or Equal conditions).

SB8 handles 64-bit values without any problem.

Friedrich

NewsArchive
01-19-2013, 03:02 AM
Friedrich - that worked - thanks as usual

Dee

--
Darrel (Dee) Witham
Professional Data Services, Inc

NewsArchive
01-19-2013, 03:03 AM
Sorry - spoke too soon.
Here is my code and the divide by 1024 is not working. My numbers athe
same except without commas.

Set Variable %NUMBER_1% to "74,590,097,776"
Set Variable %FREE_SPACE% to "1,386,891,344,000"
Set Variable %NUMBER_1% to FUNCTION:Replace(%NUMBER_1%, ,, )
Set Variable %FREE_SPACE% to FUNCTION:Replace(%FREE_SPACE%, ,, )
Set Variable %NUMBER_1% to %NUMBER_1% \ 1024 (Arithmetic & Bitwise
Operation)
Set Variable %FREE_SPACE% to %FREE_SPACE% \ 1024 (Arithmetic & Bitwise
Operation)
Display Message Box "FREE_SPACE=%FREE_SPACE%\nNUMBER_1=%NUMBER_1%" -- ""
If %NUMBER_1% Greater Than "%FREE_SPACE%" Then
Display Message Box "Number 1 greater than free space" -- ""
Else
Display Message Box "free space less than or equal to number 1" -- ""
End
Exit Installation()

Dee

--
Darrel (Dee) Witham
Professional Data Services, Inc

NewsArchive
01-19-2013, 03:03 AM
Hi Dee

There are two things you need to look at...

1) Use forwardslash / when doing your divide by 1024 (Might not be significant)
2) Your If Else logic is broken. The message for the ELSE condition would reflect the
TRUE condition.

Otherwise if I test with your numbers the comparison all works as expected.

JohnG

NewsArchive
01-19-2013, 03:36 AM
Exactly what John said!

Instead of "%NUMBER_1% \ 1024" it should be "%NUMBER_1% / 1024" and not
%FREE_SPACE% \ 1024" but "%FREE_SPACE% / 1024"

Friedrich

NewsArchive
01-21-2013, 01:43 AM
OK - I get to wear the stupid hat on Monday. Thanks

--
Darrel (Dee) Witham
Professional Data Services, Inc