Jump to content

Recommended Posts

Hi guys,
how are you today ? sea sex sun and holidays ?

I want to understand an obvious comparison fact:

I use to have many httprequests, for wich result was 'OK' or 'KO'
Now for some of these requests, the result send is 1 or 0

I got a function for doing my request, so to test the answer, instinctively i did something like

; $myvar = my_http_request() ; sometimes return 0/1 sometimes returns 'OK/KO'
$myvar = 0 ; For test
If $myvar = "OK"  Or $myvar = 1 Then
    ConsoleWrite("It's equal" & @CRLF )  ; > This is equal.
    ConsoleWrite("It's NOT equal" & @CRLF )

In this case, the comparison is always true.
Ok i understand that it compare string to integer... but why is this always true ? .. i would have understood if it was always false but why always true ?

that's all for me :)
thanks guys, kids, ladies and gentlemen  !

Link to post
Share on other sites

Though it's not recommended, if you want to compare the same variable against a string or a number, you must be explicit  :)

If $myvar == "OK"  Or $myvar = 1 Then

Details from the helpfile, 'Operators' page
Note: Care is needed if comparing mixed datatypes, as unless the == case-sensitive string operator is used, mixed comparisons are usually made numerically. Most strings will be evaluated as 0 and so the result may well not be the one expected. It is recommended to force the items being compared into the same datatype using Number/String before the comparison.

Edited by mikell
Link to post
Share on other sites

Comparison of different data types need a conversation of at least one operand to the datatype of the other.
In this case the right operand "OK" of the =-operator gets converted to a integer (the datatype of the left operand) before it's compared.
And because Int("OK" ) leads to 0 implicitly the comparison looks like: If $myvar = 0 [...]

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

    No registered users viewing this page.

  • Similar Content

    • By jonson1986
      I'm having list of words and put them into an array ($WordsList) and try to compare results with logical function if in such a condition that if letter extracted through _StringBetween doesn't exist in Array ($WordsList) then it'll show message box like "Pattern Not found" and if patter found in array then it'll skip if comparison and show last message "All Done". 
      But in my condition, the if comparison is not able to process commands upto my expectations and just show last message only.
      Please help me and guide me further how can i make this possible.
      $file = fileopen(@ScriptDir & "\source.txt", 10) $IE = _IECreate( "http://example.com", 0, 0) $source = _IEDocReadHTML($IE) FileWrite($file, $source) Global $File = @scriptdir & "\source.txt" $sText = FileRead($File) $target_source = _StringBetween($sText, "Dateuploaded</strong><span>", "</span></li><li><strong>Seeders") _ArrayDisplay ($target_source) $WordsList = ("2daysago", "1dayago") If $target_source[0] <> $WordsList Then ; Here is the problem for logical comparison MsgBox ( '', '', 'Pattern Not found') EndIf MsgBox ('', '', 'All Done')  
    • By Wicked_Caty
      I've just written a small script that compares two strings and returns the similarity of those two in %. I know of StringCompare, but I want to get a percentage and I also want to get in touch with Autoit.
      Compiling doesn't cause any problems, but actually running it does. In line 20 it has a problem with the index and says "Subscript used on non-accessible variable". What's causing that problem, and how can I solve it? Thanks! And sorry for my ugly style
    • By Servant
      I think there's only a little difference when you create a GUI program with AutoIt from developing a GUI program by writing it in C++, mostly, if you're including cURL in your project..
      Because sometimes, I feel that I can write my AutoIt script in C++ programming language.
      But of course, using AutoIt language is much easier (artificially)..
      Any thoughts (in detail) about it? And about their differences?
  • Create New...