Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#1214 closed Bug (No Bug)

InputBox() vs. date macros

Reported by: admin@… Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


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 = under WIN_XP/Service Pack 3 X86

Attachments (0)

Change History (4)

comment:1 Changed 11 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

You're comparing two strings. Cast them with Number().

No bug.

comment:2 Changed 11 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 11 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 11 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.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.