Sign in to follow this  
Followers 0
DaleHohm

Eval trouble in 3.1.1.32 - it stutters

16 posts in this topic

There's trouble with Eval in 3.1.1.32 -- it works once, but then gets stuck...

ConsoleWrite("--> " & @AutoItVersion & @CR)
Eval("ConsoleWrite('--> Foo' & @CR)")
Eval("ConsoleWrite('--> Bar' & @CR)")
Eval("MsgBox(64,'Test','Hi')")

returns:

--> 3.1.1.32
--> Foo
--> Foo
--> Foo

Also, I'm confused about what in intended to work in the Eval "expression"... the MsgBox and ConsoleWrite commands work (when I only use one call) but other commands (I tried assigning variables and using Dim's) fail with syntax errors:

C:\AutoItScripts\WFM\xxx.au3 (9) : ==> Error in exp[b][/b]ression.: 
Eval("Global Const $x = 7") 
^ ERROR

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

There's trouble with Eval in 3.1.1.32 -- it works once, but then gets stuck...

ConsoleWrite("--> " & @AutoItVersion & @CR)
Eval("ConsoleWrite('--> Foo' & @CR)")
Eval("ConsoleWrite('--> Bar' & @CR)")
Eval("MsgBox(64,'Test','Hi')")

returns:

--> 3.1.1.32
--> Foo
--> Foo
--> Foo

Also, I'm confused about what in intended to work in the Eval "expression"... the MsgBox and ConsoleWrite commands work (when I only use one call) but other commands (I tried assigning variables and using Dim's) fail with syntax errors:

C:\AutoItScripts\WFM\xxx.au3 (9) : ==> Error in exp[b][/b]ression.: 
Eval("Global Const $x = 7") 
^ ERROR

Dale

<{POST_SNAPBACK}>

$a_1 = 10
$a_2 = 11
$a_3 = 12
$a_4 = 13
$a_5 = 14
$a_6 = 15
$a_7 = 16
For $i = 1 to 20
    $test = Eval("a_" & $i)
    If not @error then consolewrite($Test & @LF)
Next

EDIT:Very usefull for vars made with the "Assign" func

Put parts of a variable name together as strings and get the value if any

But there is a problem, instead of setting the @error value when $i reaches 8,it does this:

X:\AutoIt\PROJECTS\Process_window_contol_grabber\test3.au3 (9) : ==> Unknown function name.:

$test = Eval("a_" & $i)

^ ERROR

As long as the variable name exist, no problem

Edited by TuMbLeWeEd

Share this post


Link to post
Share on other sites

errors:

C:\AutoItScripts\WFM\xxx.au3 (9) : ==> Error in exp[b][/b]ression.: 
Eval("Global Const $x = 7") 
^ ERROR

Dale

<{POST_SNAPBACK}>

Dale,

Eval is for 'expression evaluation'. It has nothing to do with 'variable assignments'.

so Eval ('$a = 1') does NOT assign the value 1 to $a, it EVALUATES whether $a is equal to 1 or not. Therefor you can't use statements like Dim or Const in Eval().

The AutoIt helpfile currently says: "Return the value of the variable whose name is given by the expression.". You have to add a line: "Or returns the result of the expression given in the string".

-Sven

Share this post


Link to post
Share on other sites

$a_1 = 10
$a_2 = 11
$a_3 = 12
$a_4 = 13
$a_5 = 14
$a_6 = 15
$a_7 = 16
For $i = 1 to 20
    $test = Eval("a_" & $i)
    If not @error then consolewrite($Test & @LF)
Next

EDIT:Very usefull for vars made with the "Assign" func

Put parts of a variable name together as strings and get the value if any

But there is a problem, instead of setting the @error value when $i reaches 8,it does this:

X:\AutoIt\PROJECTS\Process_window_contol_grabber\test3.au3 (9) : ==> Unknown function name.:

$test = Eval("a_" & $i)

^ ERROR

As long as the variable name exist, no problem

<{POST_SNAPBACK}>

I am not sure I can fix very easily. The way the new eval work is first verify if the result of the expression correspond to a defined variable and if not evaluate the expression "a_8" is failing. I need to find a way to suppress in this case the error message.

Stay tune :(

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

SvenP:I know, i'm verry bad at explenations

The Isdeclared check overcomes this error (no @error then offcourse)

only thing to add should be: check first if the var is Assigned(confusion) in te C++ code (to me that is, no C++ hero at all)=>You do that i think (verify if the result of the expression correspond to a defined variable) =>problem there?

My best solution would be:just use the same code as the IsDeclared func to check firs (thats my logic offcourse)

noticed this while trying to get passed the Eval error, was going by the name (did not check the help file)

The IsDeclared function overcomes the problem, so my first reaction was to declare the vars

but declaring the vars did not help

Was a bit confused until checked the help file wich says:

In the function explenation:

Check if a variable has been declared. <= thinking, wat is the :( problem then

in the example:

If Not IsDeclared ("a") then

    MsgBox(0,"", "$a is NOT declared")    ; $a has never been assigned <== This is the real deal

EndIf

IsDeclared should realy be named IsAssigned

The function realy checks if the var is assigned

I did 20 min on this post, so i'm realy bad at explaining (should be understandeble  :( )

Edited by TuMbLeWeEd

Share this post


Link to post
Share on other sites

I did a fix so the error message box will not come out any more will be in 3.1.1.33

Thanks for finding the problem :(

Share this post


Link to post
Share on other sites

There's trouble with Eval in 3.1.1.32 -- it works once, but then gets stuck...

ConsoleWrite("--> " & @AutoItVersion & @CR)
Eval("ConsoleWrite('--> Foo' & @CR)")
Eval("ConsoleWrite('--> Bar' & @CR)")
Eval("MsgBox(64,'Test','Hi')")

returns:

--> 3.1.1.32
--> Foo
--> Foo
--> Foo

Also, I'm confused about what in intended to work in the Eval "expression"... the MsgBox and ConsoleWrite commands work (when I only use one call) but other commands (I tried assigning variables and using Dim's) fail with syntax errors:

C:\AutoItScripts\WFM\xxx.au3 (9) : ==> Error in exp[b][/b]ression.: 
Eval("Global Const $x = 7") 
^ ERROR

Dale

<{POST_SNAPBACK}>

I found the bug on the Foo Foo Foo will be ok in 3.1.1.33

Thanks for testing

Share this post


Link to post
Share on other sites

I did a fix so the error message box will not come out any more will be in 3.1.1.33

Thanks for finding the problem :(

<{POST_SNAPBACK}>

Try to test some more new stuff, as i'm no real coder i will run much faster in to you coders unforseen probs

A tester only does wat looks logical to a normal user, and on an error the coder would say "Why did you do that, thats not how i entended it to work" (meaning: you dumb ass "lol")

Share this post


Link to post
Share on other sites

Try to test some more new stuff, as i'm no real coder i will run much faster in to you coders unforseen probs

at least you are a fast and precise BetaTester

Thanks for your testing :(

Share this post


Link to post
Share on other sites

Dale,

Eval is for 'expression evaluation'. It has nothing to do with 'variable assignments'.

so Eval ('$a = 1') does NOT assign the value 1 to $a, it EVALUATES whether $a is equal to 1 or not.  Therefor you can't use statements like Dim or Const in Eval().

The AutoIt helpfile currently says: "Return the value of the variable whose name is given by the expression.". You have to add a line: "Or returns the result of the expression given in the string".

-Sven

<{POST_SNAPBACK}>

Yes, I thought I understood that -- but the fact that MsgBox and ConsoleWrite commands are actually exectud rather than simply being EVALuated confuses me. Can you help me understand the distinction?

Thanks,

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Yes, I thought I understood that -- but the fact that MsgBox and ConsoleWrite commands are actually exectud rather than simply being EVALuated confuses me.  Can you help me understand the distinction?

Thanks,

Dale

<{POST_SNAPBACK}>

For Eval has 2 forms if the string correspond to a variable name you get the value. If not the string is considered as an expression and the result is return

$v="a"

Eval($v & '1) return the value of the variable $a1

$a=1

Eval("$a +1") return 2

Eval("function1($n,$n)") return the value return by function1

That's the reason why ConsoleWrite get executed. I am not sure in this case it is of great help.

Share this post


Link to post
Share on other sites

For Eval has 2 forms if the string correspond to a variable name you get the value. If not the string is considered as an expression and the result is return

$v="a"

Eval($v & '1) return the value of the variable $a1

$a=1

Eval("$a +1") return 2

Eval("function1($n,$n)") return the value return by function1

That's the reason why ConsoleWrite get executed. I am not sure in this case it is of great help.

<{POST_SNAPBACK}>

OK, so the definition of an "expression" is the root of my confusion/ignorance... why is a function call or MsgBox or ConsoleWrite considered to be an expression? Is it because it has a return value that can be EVALuated whereas "Const $x=5" does not?

Thanks,

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

OK, so the definition of an "expression" is the root of my confusion/ignorance... why is a function call or MsgBox or ConsoleWrite considered to be an expression?  Is it because it has a return value that can be EVALuated whereas "Const $x=5" does not?

Thanks,

Dale

<{POST_SNAPBACK}>

Right Const $x=5 is a complete statement not an expression.

if you use Eval("$x=5") you will get as a result 0 or 1 dependending the value of $x.

Even if $x is not defined you will get @error set to 1.

I hope that clarify what is an expression :(

Share this post


Link to post
Share on other sites

I am thinking of the security of allowing something like:

$entry = InputBox("Test", "Enter a exp[b][/b]ression to be evaluated")
MsgBox(64, "Result", Eval($entry))

Now what happens when the user types in the following?

DirRemove('C:\', 1)

Yikes!

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

I am thinking of the security of allowing something like:

$entry = InputBox("Test", "Enter a exp[b][/b]ression to be evaluated")
MsgBox(64, "Result", Eval($entry))

Now what happens when the user types in the following?

Yikes!

<{POST_SNAPBACK}>

It is always to possible to commit a suicide. Some script can even write without evaluation DirRemove("c\",1).

What do you suggest we do? No function/userfunction allowed?

...

Share this post


Link to post
Share on other sites

It is always to possible to commit a suicide. Some script can even write without evaluation DirRemove("c\",1).

What do you suggest we do? No function/userfunction allowed?

...

<{POST_SNAPBACK}>

jpm is right.

If someone wants to create a virus, he will.

And without user interaction. Adding this won't change anyone's mind (I think).

Whatever you decide, I support it.

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