VBEval vs. VBRun

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

VBEval vs. VBRun

Post by armsys » Wed May 21, 2008 8:34 am

What's the difference between VBEval and VBrun?
Programmatically, they appear the same.
For example,
VBStart
VBSend
Let>String= 123
VBRun>Trim(%String%),String
VBEval>Trim("%String%"),String
However, VBEval causes error 1033, while VBRun runs successfully.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 21, 2008 8:45 am

VBEval evaluates a VBScript expression, and returns the result.

VBRun runs a VBScript subroutine. Subroutines do not have results. VBRun has no means of returning a result.

In your code VBSEnd should be VBEnd.

With your code the VBRun statement will do nothing and will not trim the string. Nothing is returned. But the VBEval line works because Trim is a VBScript function and VBEval gets the result of it.

Use VBRun when you just want to call a VBScript subroutine. Use VBEval when you want to evalate a VBScript expression (which could be a function) and return the result.

VBRun takes the subroutine name, and then any parameters:

VBRun>SubroutineName,parm1,parm2,parm3

VBEval takes a valid VBScript expression and a variable to store the result in:

VBEval>Expression,result
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Wed May 21, 2008 9:17 am

Thanks for your uusal fast reply.
1. It's my typo error. It should read VBEnd.
2. The following script should help you reproduce Error 1033
VBStart
VBEnd
Let>String= 123
ConCat>String,%CRLF%
VBEval>trim("%String%"),String
Msg>String

Please help. Thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 21, 2008 9:46 am

The CRLF is the problem. You are passing multiple lines into VBScript. It doesn't like that. If you want CRLFs, remove them before the VBScript (use StringReplace) and add them after:

StringReplace>String,CR,,String
StringReplace>String,LF,,String
VBEval>trim("%String%"),String
Msg>String
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 21, 2008 9:54 am

Or you can do this:

VBStart
VBEnd
Let>String= 123
ConCat>String,%CRLF%
StringReplace>String,CRLF," & vbCRLF & ",String
VBEval>trim("%String%"),String
Msg>String

That replaces the physical CRLF with VBScript's placeholder for it. Then it can cope.
Last edited by Marcus Tettmar on Thu May 22, 2008 7:24 am, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Wed May 21, 2008 10:15 am

Thanks for solving Error 1033, which tortured me for days. I suspected CRLF was the culprit, but wasn't so sure. I wouldn't expect VBScript's incompatibility. Neither did I know that VBRun actually won't return any result. Thanks for teaching me so many scripting tricks.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts