Hi Nico,

This is a lot to try and explain at once.  ExecuteGlobal is a command which is 
seldom used, and really should be used more in advanced programming; it has 
little to do with starting to learn scripting or simple scripts.

ExecuteGlobal is used when you need to add a variable declaration (for a global 
variable), or, when you need to add a sub or function to your program from 
within your program.  It's difficult to explain why this might ever be useful.

The way you have your executeGlobal, it's actually doing nothing at all, 
because it's running at the global level, but you don't have these variables 
declared at the global level (or scope).

As for Eval(), it's a function which returns the value of an expression; it 
cannot be used to execute a command (as you try to do at first, where you are 
trying to assign a value to the result variable).  Eval() won't do this; what 
it is doing is testing to see if the current value in result is equal to the 
expression on the other side of the equals sign (a+b), and then eval() returns 
false or true here.

In the later use of Eval(), where you assign it's result to the variable 
result, this is the more proper use of the Eval() function; and when you have 
values in the variables a and b, then you'll get the value 15 returned by 
eval().

Again, Eval() is not a function usually used by beginning scripters; it's used 
most often when you aren't sure which variables are to be used in your 
expression, and so you could build up your expression in a string, where you 
add the variable names as your program executes through various options.

Let me know if you have further questions, and I'll try again if I didn't 
answer your questions this first time.

Hth,

Chip




Chip Orange
Florida Public Service Commission
Computer Systems Analyst
850-413-6314


-----Original Message-----
From: Scripting 
[mailto:scripting-bounces+corange=psc.state.fl...@lists.window-eyes.com] On 
Behalf Of Nico Valster via Scripting
Sent: Friday, November 27, 2015 6:02 AM
To: scripting@lists.window-eyes.com
Subject: ExecuteGlobal and its cousins Eval and Execute

Based on
<https://www.gwmicro.com/Support/Knowledge_Base/?kbnumber=GWKB2035>
https://www.gwmicro.com/Support/Knowledge_Base/?kbnumber=GWKB2035

I wrote the script as shown at the end of this email

Since ExecuteGlobal did not behave as I expected, I did some searching on
the web and found Eval

The call to ExecuteGlobal and the first call to Eval, both result in "No
error" and 0 as result

The second call to Eval results in the expected 15.

The call to Execute results in the expected 50

 

What do I do wrong with the call to ExecuteGlobal and the first call to Eval
?

 

 

 

Option Explicit

 

Dim myHotkey : Set myHotkey = Keyboard.RegisterHotkey("Control-Shift-1",
"MyFunction")

 

Sub MyFunction()

        On Error Resume Next

         Dim result : result = 0

         Dim a : a = 5

         Dim b : b = 10

         ExecuteGlobal "result = a + b"

         If Err Then

                   call MsgBox("error")

         Else

                   call MsgBox("No error")

         End If

         MsgBox result

 

         Eval "result = a + b"

         If Err Then

                   call MsgBox("error")

         Else

                   call MsgBox("No error")

         End If

         MsgBox result

 

         result = Eval( "a + b" )

         If Err Then

                   call MsgBox("error")

         Else

                   call MsgBox("No error")

         End If

         MsgBox result

 

         Execute "result = a * b"

         If Err Then

                   call MsgBox("error")

         Else

                   call MsgBox("No error")

         End If

         MsgBox result

 

End Sub        

 

 

 

 

Met vriendelijke groet, kind regards
Nico Valster
 <http://www.babbage.com/> www.babbage.com
 <http://www.youtube.com/results?search_query=babbagecom> Babbage op Youtube
klik hier:
Onyxdijk 199
4706 LL Roosendaal
tel. : 0165-536156
KVK: 20065000

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com/attachments/20151127/34531961/attachment.htm>
_______________________________________________
Any views or opinions presented in this email are solely those of the author 
and do not necessarily represent those of Ai Squared.

For membership options, visit 
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/corange%40psc.state.fl.us.
For subscription options, visit 
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at 
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author 
and do not necessarily represent those of Ai Squared.

For membership options, visit 
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit 
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at 
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com

Reply via email to