Jump to content

Can values be assigned to object attributes using Assign, Execute, Eval?


Recommended Posts

Hello,

following my previous question, I have moved all potentially instable object interactions into Executes. But it Looks like "="-assignments to object Attributes cannot be done with Execute, only method calls. Using an "$obj = 1" construct, it compares (Eval) instead of sets (Execute) the value.

I have tested multiple different combinations, using Execute and Assign, but it seems not to work with object Attributes. :-(

Quote

 

Local $oIE = _IECreate("http://leo.org")

Local $var = ""

ConsoleWrite("a1) Assign to var: " & Assign("var", "test") & @CRLF)

ConsoleWrite("a2) var value: " & $var & @CRLF)

ConsoleWrite("a3) Assign to com attribute: " & Assign("oIE.document.title", "test") & @CRLF)

ConsoleWrite("a4) com attribute value: " & $oIE.document.title & @CRLF)

$var = ""

ConsoleWrite("e1) Execute assign to var: " & Execute("$var=""test""") & @CRLF)

ConsoleWrite("e2) var value: " & $var & @CRLF)

ConsoleWrite("e3) Execute assign to com attribute: " & Execute("$oIE.document.title=""test""") & @CRLF)

ConsoleWrite("e4) com attribute value: " & $oIE.document.title & @CRLF)

 

Gives following Output:

Quote

 

a1) Assign to var: 1

a2) var value: test

a3) Assign to com attribute: 0

a4) com attribute value: LEO.org - Ihr Sprachangebot im Web

e1) Execute assign to var: False

e2) var value:

e3) Execute assign to com attribute: False

e4) com attribute value: LEO.org - Ihr Sprachangebot im Web

 

The assign Action using apply (a3) Fails, while assigning it directly, without Assign() works fine.

The execute versions compare and do not assign, in both cases. Though, the "Execute" topic in the help file says it executes, not evaluates.

I have found a similar, old thread, which explains this behavious but does not give a solution. https://www.autoitscript.com/forum/topic/110228-pass-object-property-as-a-variable/  

Is there a way to assign to a com object's Attribute? Or is there anything new to this unexpected behaviour of Execute (at least compared to the help file description and Python's exec).

 

Any help is appreciated, and thank you for all the help so far.

Regards, Michael

 

Link to comment
Share on other sites

Why are you trying to use Assign and Execute? There are usually much easier and better ways to do whatever it is you're trying to Mickey Mouse together.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

3 minutes ago, BrewManNH said:

Why are you trying to use Assign and Execute? There are usually much easier and better ways to do whatever it is you're trying to Mickey Mouse together.

That is part of the Workaround described here  https://www.autoitscript.com/forum/topic/191838-stop-fatal-errors-from-crashing-script-run/

I have to assign to a DOM element of a Website that has a script running in the Background and cutting/replacing parts of the dom structure. So I cannot make sure the element exists, before actually trying to assign to it. When by Chance, the targeted DOM element was cut just before I try to Access it, two Errors occur. 1st the com-error for referring to a non existent object or Attribute and 2nd a fatal AutoIt error for assigning to the non existent item. I can catch the com error with an ObjEvent handler. But I cannot stop the AutoIt error from stopping the script run. Running the Actions by Execute will throw the com error and savely return 1 in case of a fatal AutoIt error. That's why I wanted to place all critical com Actions into Execute Statements and evaluate the @error codes. I hope that explains the Approach.

However, I am open for better Solutions. It's just my current state of work.

 

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

×
×
  • Create New...