BobWolfe Posted March 10, 2007 Posted March 10, 2007 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)
Xenobiologist Posted March 10, 2007 Posted March 10, 2007 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
xcal Posted March 10, 2007 Posted March 10, 2007 Can use Number(), too. How To Ask Questions The Smart Way
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now