VB Evaluate

<< Click to Display Table of Contents >>

Navigation:  Actions > Script tools >

VB Evaluate

This action allows to calculate an expression value and then save it into a variable. The expression has to be written according to the syntax of VB script language. The documentation for the language can be read on the Microsoft site: http://msdn.microsoft.com/en-us/library/t0aew7h6(v=vs.84).aspx

The action also allows to connect the function library from an external file or directly in an additional script.

For example, try to calculate the expression

sum(5,6) + multi(3,4)

And we get the error. The VB Script language doesn't contain functions sum and multi.

To solve this, it is possible to specify a little library of user functions:


function sum(a, b)

 sum = a + b

end Function


function multi(a, b)

 multi = a * b

end function


In this case the action calculates the result without any troubles. The given example is too simple and is cited for the demonstration solely.


Another example. Calculate the factorial of a number. Such function is absent in VB Script. But it is easy to evade. It takes only to create the simply function:


function factorial(a)

 if a > 30 then

   'this is synthetic limitation

   err.raise 1, , "Parameter more than 30"

 end if


 res = 1

 for i = 1 to a

     res = res * i



 factorial = res

end function



Now we easy can calculate the expression:


Given possibility allows to do some specific calculations, that are difficult to be written in one line.




Expression To Evaluate

Write down the expression whose value needs to be calculated. The expression has to be made according to the syntax of VB Script.


Assign Result to Variable

Enter the name of the variable into which it is necessary to save the result.





Load VB Script from File

Load the library of additional functions from an external file. Enter a file name or choose it interactively.

The file name can be empty. In this case the action works only with standard functions and objects of VB Script.


Use Internal Script

If you want to specify functions directly in a task, choose this option. To edit a script, click the button Edit Script. You can see the editor like in the action VB Script.

The text of a script can be empty. In this case the action works only with standard functions  and objects of VB Script.



note Related Topics

JS script

JS Evaluate

VB Script

RoboTaskApp object