Jump to content
Faalamva

[SOLVED] Comparison between Strings and Numbers : Why does it match ?

Recommended Posts

Faalamva

Hello,

A strange behaviour occured in my code, so I've stripped and stripped again its content, until I could confine and identify the very cause of the malfunction.

Put under its simplest form, here it is : this kind of comparison is working, although at first sight it's no so evident why it is :

If "338a" = 338 Then
    MsgBox(0, "", "Why oh why ?")
EndIf

I understand that comparing a string with an integer is a bit odd, however in the original code, I'm comparing variables from an array, and this array if filled from an Excel file through the _Excel_RangeRead function. The column of the Excel file can contain random values : some of them are 338 (interpreted as integer) and some others are 338a (interpreted as string). :)

Now I can solve the problem by forcing the comparison like this : String(variable1) = String(variable2) where variable1 and variable2 can be of any type (coming from the Excel file).

However I'd like to know the very reason why this comparison is working in the first place ? Please enlighten me ! :lol:

Faalamva

Edited by Faalamva

Share this post


Link to post
Share on other sites
jchd

Use == instead of =


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jchd

Sorry I didn't have much time for lengthy explanation. Nice to know you've got it.

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

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

×