Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Using Eval() to retrieve object properties

$
0
0
A Merry (late) Christmas!

I was working on something, and am trying to shorten some code.

;Local $eTemp = "err.description is: " & @TAB & $oError.description & _
; "err.windescription:" & @TAB & $oError.windescription & _
; "err.number is: " & @TAB & Hex($oError.number, 8) & _
; "err.scriptline is: " & @TAB & $oError.scriptline & _
; "err.source is: " & @TAB & $oError.source


Local $eTemp = 'description.windescription.number.scriptline.source'
$eTemp = StringSplit($eTemp, '.')
For $i = 1 To $eTemp[0]
ConsoleWrite($eTemp[$i] & @TAB & Eval("oError" & '.' & $eTemp[$i]) & @LF)
Next


As you can see in the initial commented code, the method used to display the errors is much longer and space-consuming. I am trying to simplify it below. Problem is, I don't know how to retrieve those variables using Eval (which is supposed to convert a variable into a string).

While I work on it, any help would be greatly appreciated.

Have a great day guys!

EDIT: I'm sure we all don't like this when it happens :P

I spent almost half an hour tinkering with Eval and doing other stuff, experimenting, to try and get it to work. Moments after posting for help I found the solution. Instead of using Eval() I used Execute like so:

Execute("$oError." & $eTemp[$i])

Thanks for your time though!

Viewing all articles
Browse latest Browse all 12506

Trending Articles