Jump to content

Difference between = and ==


Recommended Posts

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

Link to comment
Share on other sites

= 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
Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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. :)
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...