#1214 closed Bug (No Bug)
InputBox() vs. date macros
Reported by: | admin@… | Owned by: | |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | 3.3.0.0 | Severity: | None |
Keywords: | Cc: |
Description
I stumbled across an issue while trying to use conditional statements to compare date macros and values entered through InputBox(). Run the script below and see yourself. You'll only get a correct result if you enter either 0 or 1.
$val1 = @MON $val2 = InputBox ( "test", "Just press enter here." & @CR & @CR & "For your information: $val1 = @MON = " & $val1 & @CR & @CR & "The value below is: $val2 = @MON-3 = " & (@MON-3), @MON-3 ) If $val1 > $val2 Then MsgBox ( 0, "Result", "$val1 > $val2 : " & $val1 & " > " & $val2 & @CR & @CR & "$val1 is bigger. Perfect! :)" ) If $val2 > $val1 Then MsgBox ( 0, "Result", "$val2 > $val1 : " & $val2 & " > " & $val1 & @CR & @CR & "AutoIt defines $val2 as bigger!??")
Environment = 3.3.0.0 under WIN_XP/Service Pack 3 X86
Attachments (0)
Change History (4)
comment:1 Changed 15 years ago by Valik
- Resolution set to No Bug
- Status changed from new to closed
comment:2 Changed 15 years ago by admin@…
Ok thanks. I'll test that.
It's a bit confusing that AutoIt will correctly compute $val1 - $val2 = 3 .
comment:3 Changed 15 years ago by Valik
It's not confusing if you think about it. The only defined context where the minus operator is defined is with numbers. You cannot subtract strings, for example, so anything that's not already a number will be implicitly cast to a number. However, there is a defined context for strings as well as numbers when using the <, >, <= or >=. If strings are compared then it's a lexicographical comparison. If numbers are passed then a numeric comparison is performed. No implicit cast is performed to number from strings containing numbers because that is an ambiguous case where AutoIt can't determine the correct thing to do.
comment:4 Changed 15 years ago by anonymous
Ah that clarifies some things. Thanks. I'll post to the forum first next time.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
You're comparing two strings. Cast them with Number().
No bug.