// Eval Example
/* Eval execute a string as a Function */
var x;
x = 5;
NSB.Print(eval("x"));
eval("x = x * 10");
NSB.Print(x);
No edit summary |
No edit summary |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 5: | Line 5: | ||
Eval returns a value created by executing an expression as if it were a Function procedure. The required parameter, ''string'', is a string expression that is executed. If multiple statements are to be executed, separate them with a carriage return (vbCRLF). The temporary, virtual procedure that gets created has all program variables passed in by value, so the variables are unmodifiable by the Eval function. | Eval returns a value created by executing an expression as if it were a Function procedure. The required parameter, ''string'', is a string expression that is executed. If multiple statements are to be executed, separate them with a carriage return (vbCRLF). The temporary, virtual procedure that gets created has all program variables passed in by value, so the variables are unmodifiable by the Eval function. | ||
The code in the string is evaluated as JavaScript code. See the TechNote | The code in the string is evaluated as JavaScript code. See the TechNote 04 “The role of JavaScript, HTML5 and WebKit”. | ||
== Example == | == Example == | ||
< | <tabber> | ||
JavaScript= | |||
<syntaxhighlight lang="JavaScript"> | |||
// Eval Example | |||
/* Eval execute a string as a Function */ | |||
var x; | |||
x = 5; | |||
NSB.Print(eval("x")); | |||
eval("x = x * 10"); | |||
NSB.Print(x);</syntaxhighlight> | |||
|-| | |||
BASIC= | |||
<syntaxhighlight lang="vb.net"> | |||
Rem Eval Example | Rem Eval Example | ||
'Eval execute a string as a Function | 'Eval execute a string as a Function | ||
Line 17: | Line 30: | ||
Eval("x = x * 10") | Eval("x = x * 10") | ||
Print x | Print x | ||
</ | </syntaxhighlight> | ||
</tabber> | |||
== Output == | == Output == | ||
Line 23: | Line 37: | ||
<pre> | <pre> | ||
5 | 5 | ||
50 | |||
</pre> | </pre> | ||
Line 31: | Line 45: | ||
[[Category:Language Reference]] | [[Category:Language Reference]] | ||
[[Category:Strings]] |
Eval(string)
Eval returns a value created by executing an expression as if it were a Function procedure. The required parameter, string, is a string expression that is executed. If multiple statements are to be executed, separate them with a carriage return (vbCRLF). The temporary, virtual procedure that gets created has all program variables passed in by value, so the variables are unmodifiable by the Eval function.
The code in the string is evaluated as JavaScript code. See the TechNote 04 “The role of JavaScript, HTML5 and WebKit”.
// Eval Example
/* Eval execute a string as a Function */
var x;
x = 5;
NSB.Print(eval("x"));
eval("x = x * 10");
NSB.Print(x);
Rem Eval Example
'Eval execute a string as a Function
Dim x
x = 5
Print Eval("x")
Eval("x = x * 10")
Print x
5 50