# Comparing variant string variables as numbers

## Recommended Posts

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 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)

_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 on other sites

Can use Number(), too.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...