Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Difference between = and ==


  • Please log in to reply
81 replies to this topic

#1 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 07 August 2012 - 02:56 PM

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







#2 jaberwacky

jaberwacky

    RegExp("\m/")

  • Active Members
  • PipPipPipPipPipPip
  • 3,222 posts

Posted 07 August 2012 - 03:00 PM

= 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, 07 August 2012 - 03:00 PM.


#3 water

water

    ?

  • MVPs
  • 15,743 posts

Posted 07 August 2012 - 03:01 PM

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, 07 August 2012 - 03:02 PM.

UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#4 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 07 August 2012 - 03:05 PM

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.

#5 water

water

    ?

  • MVPs
  • 15,743 posts

Posted 07 August 2012 - 03:08 PM

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.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#6 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 07 August 2012 - 03:16 PM

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

#7 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 08 August 2012 - 10:20 AM

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

#8 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 08 August 2012 - 10:21 AM

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

#9 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 08 August 2012 - 01:13 PM

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.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#10 Baksteen

Baksteen

    Seeker

  • Active Members
  • 21 posts

Posted 08 August 2012 - 01:19 PM

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, 08 August 2012 - 01:20 PM.


#11 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 08 August 2012 - 01:22 PM

Yes, click is a method.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#12 notsure

notsure

    Polymath

  • Active Members
  • PipPipPipPip
  • 210 posts

Posted 09 August 2012 - 08:20 AM

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

#13 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 09 August 2012 - 09:43 AM

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.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#14 notsure

notsure

    Polymath

  • Active Members
  • PipPipPipPip
  • 210 posts

Posted 09 August 2012 - 10:59 AM

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, 09 August 2012 - 11:00 AM.


#15 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 09 August 2012 - 11:17 AM

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

Edited by trancexx, 09 August 2012 - 11:18 AM.

...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#16 notsure

notsure

    Polymath

  • Active Members
  • PipPipPipPip
  • 210 posts

Posted 09 August 2012 - 11:28 AM

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, 09 August 2012 - 11:28 AM.


#17 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 09 August 2012 - 11:36 AM

It's not about lying, it's about not understanding, not knowing, bad coding, stuff like that.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#18 notsure

notsure

    Polymath

  • Active Members
  • PipPipPipPip
  • 210 posts

Posted 09 August 2012 - 11:41 AM

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.

#19 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 09 August 2012 - 11:47 AM

Behaves like what?
Use your head. Think, think.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#20 Exit

Exit

  • Active Members
  • PipPipPipPipPipPip
  • 690 posts

Posted 09 August 2012 - 11:49 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users