Accessing variable inside Vbstart-VBEnd block

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
aks
Newbie
Posts: 18
Joined: Wed Oct 15, 2008 8:54 am

Accessing variable inside Vbstart-VBEnd block

Post by aks » Thu Oct 16, 2008 3:03 pm

Hi,

let>res=This is a test message
VBSTART
dim res
msg=res
MsgBox(msg)
VBEND

What is missing in the above code snippet? Or the only way to link vbscript and macro is to use function and sub commands of vbscript? Meaning:

let>res=This is a test message
VBSTART
Sub DisplayMessage (msg)
MsgBox msg
End Sub
VBEND
VBRun>DisplayMessage,res

??

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

Post by Marcus Tettmar » Thu Oct 16, 2008 3:56 pm

You can use VBEval to evaluate a VBScript expression. A VBScript expression could be just a variable:

Code: Select all

VBSTART
  dim res
  res = "fred"
VBEND

VBEval>res,myRes
MessageModal>myRes
The VBEval statement is evaluating the value of res which of course is "fred".

Often we need to use both methods. E.g. you may VBEval a VBScript function which creates an array or modifies a set of global VBScript variables which you later might want to evaluate in MacroScript using VBEval.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

aks
Newbie
Posts: 18
Joined: Wed Oct 15, 2008 8:54 am

Post by aks » Fri Oct 17, 2008 9:40 am

Hi Marcus,

Same way how can i access variable set using macro inside the vb block?
if i do:
let>msg=hello world
vbstart
msgBox msg
vbend

If i execute this code vb msg box is empty. I have also tried declaring the msg variable global inside the vbblock using dim. Still i dont get the message.

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

Post by Marcus Tettmar » Fri Oct 17, 2008 10:15 am

In this case you must pass the value to a VBScript sub/function. The VBScript must appear before the VBRun/VBEval:

Code: Select all

VBSTART
  Sub DoSomething(x)
     MsgBox x
  End Sub
VBEND

VBRun>DoSomething,Hello World
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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