Jump to content

Recommended Posts

Posted

Yep, that's right.  When I execute this simple IF statement, it comes out true!

if 0 = "FFFFFF" then msgbox(0,"","same")

As expected, issuing

if 0 = "0" then msgbox(0,"","same")

comes out true.

But

if 0 = "1" then msgbox(0,"","same")
if 1 = "FFFFFF" then msgbox(0,"","same")

are both false.

If I understand AutoIT's variable typing system, numbers (e.g. 1 without quotes) can be compared to numeric strings (e.g. "1" with quotes) and come out true.  But how is 0 = "FFFFFF"?

I missed something, right?

Posted
  On 1/20/2014 at 4:24 PM, SlowCoder74 said:

But how is 0 = "FFFFFF"?

Because comparing an int with a string the string gets converted to a int, which in this case is 0. Do you want 'FFFFFF' to be 0xFFFFFF?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Moderators
Posted

SlowCoder74,

Does this make it any clearer? ;)

If 0 = Number("FFFFFF") Then MsgBox(0, "", "same" & @CRLF & Number("FFFFFF"))
Your original code was implicitly asking AutoIt to convert the string into a number - with the results you see above.

Comparing numbers and strings will always lead to problems - best to force each side to the type you want to compare. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...