Sign in to follow this  
Followers 0

Difference between = and ==

82 posts in this topic

#1 ·  Posted

Hello,

Today I was working on a script for a website. I was trying to make my script click on a <TD> element.

It works now, but after allmost searching for 2 hours why my following code did not execute the $oQuery.click code but did execute the msgbox right above it:

_IETagNameGetCollection($oIE, "TD")
For $x = 0 To @extended - 1
$oQuery = _IETagNameGetCollection($oIE, "TD", $x)
If _IEPropertyGet($oQuery, "outertext") = "Controle & Oplevering" Then
MsgBox(1, "", "")
$oQuery.click
ExitLoop
EndIf
Next
_IELoadWait($oIE)

After changing this line

If _IEPropertyGet($oQuery, "outertext") = "Controle & Oplevering" Then

to:

If _IEPropertyGet($oQuery, "outertext") == "Controle & Oplevering" Then

It suddenly not only pops up the messagebox but also does the $oquery.click perfectly fine.

Could someone care to explain me why this works this way?

Kind regards,

Baksteen

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

= Tests if two values are equal. e.g. If $var= 5 Then (true if $var equals 5). Case insensitive when used with strings.

== Tests if two strings are equal. Case sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used for string comparisons that need to be case sensitive.

Edited by LaCastiglione

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The difference between "=" and "==" is that "=" is case insensitive ("a" = "A"), whereas "==" does an exact match ("a" <> "A").

I can't explain why your script works with "==" and didn't with "=".

In such a case I would suggest to split the command and do some error checking:

$sResult = _IEPropertyGet($oQuery, "outertext")
If @error Then ... ; do some error handling
If $sResult = "Controle & Oplevering" Then
Edited by water

My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#4 ·  Posted

yeah, the weird thing is it did execute the msgbox code, but not the following line after it, when using a single '='

When using double '==' it executes all the following code.

The explanation from lacastiglione does not explain that...

Your's (water) is more usefull, even though it doesn't answer the question it might help better in the future. Thanks for that.

Share this post


Link to post
Share on other sites

#5 ·  Posted

So the comparison is true if you use "=" or "==" but

$oQuery.click
fails when used with "=".

As you use the IE UDF I would make sure that the COM error handler is activated and gives you detailed error information when problems with objects are encountered.


My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#6 ·  Posted

So the comparison is true if you use "=" or "==" but

$oQuery.click
fails when used with "=".

As you use the IE UDF I would make sure that the COM error handler is activated and gives you detailed error information when problems with objects are encountered.

You are right, I totally forgot about the error handler. I will check this out tomorrow as I'm going home right now and am tired. :)

Share this post


Link to post
Share on other sites

#7 ·  Posted

With or without error handler doesn't change anything. The script doesn't throw any errors at all. See my console (paths are edited out, can't post any corporate information):

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "" /UserParams

+>12:15:36 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0413 Keyboard:00020409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X86)

>Running AU3Check (1.54.22.0) from:C:Program FilesAutoIt3

+>12:15:36 AU3Check ended.rc:0

>Running:(3.3.8.1):C:Program FilesAutoIt3autoit3.exe ""

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

+>12:15:44 AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 10.526

Share this post


Link to post
Share on other sites

#8 ·  Posted

Anyway, I now know to try double == when there are problems with single = ... Hopefully the devs will take a look at this at some point (or maybe they are able to explain why this happens).

Share this post


Link to post
Share on other sites

#9 ·  Posted

Youu mixed up two, three different things.

If you want to call object's method then use braces after the method name.

If you don't do that the call may fail.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi Trancexx,

Thanks for your reply.

Do you mean I should use $oQuery.click() instead of $oQuery.click ?

Or do I get it wrong?

Sorry if I'm misunderstanding, I'm still in early stages of learning to work with methods.

Edited by Baksteen

Share this post


Link to post
Share on other sites

#11 ·  Posted

Yes, click is a method.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#12 ·  Posted

That still does not explain why the "==" executes the code correctly and the "=" does not.

Share this post


Link to post
Share on other sites

#13 ·  Posted

That's very likely just bad coding. I say that problem doesn't exist.

Anyone can prove me wrong of course. Write some (good) code that would show the issue.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

The problem does exist, i tried to reproduce it by using as much HTML code as the original site has but i can't reproduce it. It seems like the website itself is coded in a way which is causing this behaviour (eventho its W3C compatible).

(Actually; i'm not "baksteen" but i've seen the problem occur. At my PC and his.)

Edited by notsure

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

An I've heard people saying Earth is round. I guess ausies have capability of hanging upside down then. Come on!

Edited by trancexx

 

.

eMyvnE

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

An I've heard people saying Earth is round. I guess ausies have capability of hanging upside down then. Come on!

I can record it on video if you like. But then again, i think it's the website which is causing the problem, not AutoIT.

Also, why would we lie about this happening, rofl.

Edited by notsure

Share this post


Link to post
Share on other sites

#17 ·  Posted

It's not about lying, it's about not understanding, not knowing, bad coding, stuff like that.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#18 ·  Posted

So $oQuery.click is bad coding and should be $oQuery.click()... i understand, you told that before, but it does not _explain_ why the website behaves like that. That's what i'm trying to figure out.

Share this post


Link to post
Share on other sites

#19 ·  Posted

Behaves like what?

Use your head. Think, think.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#20 ·  Posted

perhaps there are two instances of the string. One with exact case spelling and one with other spelling.

Just remove the "exitloop" and look if there are more than one matching events.

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
Sign in to follow this  
Followers 0