Jump to content

0 = "String" (True statement)


Recommended Posts

so uh i've been away from autoit for a long time, about a week ago i picked it back up.. not that i was ever much of a writer to start with :idea:

anyway i've just about got the rough outline of what im working on when i ran into a problem.

one of the functions i wrote was causing chaos, took me the better part of 2 hours to hunt down what it was.

when the function returned 0 and then was compared to a "string" no matter what the string was autoit thought it was true.

so for example

If 0 = "yes" Then Msgbox(0,"Msgbox", "TRUE")

it seems i can avoid this by just making the comparison case sensitive with ==

like wise using Return("0") instead of Return(0) also works.

im not sure if changing the return to a string will rather then a integer will work in all cases.. in any event i'd like to know why 0 = "string" is a true statement and what are my options beyond what i've already mentioned.

Link to comment
Share on other sites

The numeric value of your text is indeed 0 (zero). You are comparing a number to a string, which you cannot do, so autoit will compare the numeric value of you string with the number.

For example:

$text = 'any text here'
MsgBox(0, "All text = 0", Number($text))

If 0 = $text Then
    Msgbox(0,"Num to String", "TRUE")
Else
    Msgbox(0,"Num to String", "FALSE")
EndIf

If Number(0) = Number($text) Then
    Msgbox(0,"Num to Num(text)", "TRUE")
Else
    Msgbox(0,"Num to Num(text)", "FALSE")
EndIf

If String(0) = String("yes") Then
    Msgbox(0,"String to String", "TRUE")
Else
    Msgbox(0,"String to String", "FALSE")
EndIf
Link to comment
Share on other sites

hmm ok but i thought autoit did'nt have specific datatypes.

example "5" + "2" = 7

like wise "5" + 2 = 7

even though they're expressed in string form... so i dont know why i can't compare 0 to string, *scratches head*

seems a double standard here.

i probably would'nt run into this problem except i need the script im working on to read line for line a file and then act accordingly.. normally the file will contain integer however a few control strings are added.

"load" & "loop", for user friendliness i like to not do a case sensitive compare.

ok i found another solution, adding "" to a it seems to convert the integer to a string.

example

If 0 & "" = "yes" Then Msgbox(0,"Msgbox", "TRUE")

no msgbox.. cause it's now false..

so im sitting her wondering if i should just do this from the functions return, or if i should do it at the comparison.

the functions i'd like ot use in other things im not sure if returning 0 in string form "0" would have any impact on other uses, probably not...

opinions?

Edited by JoeSixpack
Link to comment
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
 Share

  • Recently Browsing   0 members

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