Sign in to follow this  
Followers 0
BobWolfe

Comparing variant string variables as numbers

3 posts in this topic

I was extracting numbers from a text file and trying to find the maximum of them. The max was 9999, which surprised me.

Then I realized the numbers were being compared alphabetically.

The extract below shows the problem with the last comparison showing the surprising result that that 12142 <7979

;Problem with comparing variant variables

;Strings compare correctly to numbers

;Strings do not compare correctly as numbers

;How do I fix this?

$IID = "12142"

$MaxIID="7979"

$Q = (10000 < $MaxIID)

MsgBox(0,"True? " & 10000 & " < " & $MaxIID,$Q)

$Q = (10000 > $IID)

MsgBox(0,"True? " & 10000 & " > " & $IID,$Q)

$Q = ($IID < $MaxIID)

MsgBox(0,"True? " & $IID & " < " & $MaxIID,$Q)

Share this post


Link to post
Share on other sites



Hi,

you mean...?

$IID = "12142"
$MaxIID = "7979"
$Q = (10000 < $MaxIID)
MsgBox(0, "True? " & 10000 & " < " & $MaxIID, $Q)
$Q = (10000 > $IID)
MsgBox(0, "True? " & 10000 & " > " & $IID, $Q)
$Q = (Int($IID) < Int($MaxIID))
MsgBox(0, "True? " & $IID & " < " & $MaxIID, $Q)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0