VBRun Parameters Passed by Value or Reference

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
MikeB941
Newbie
Posts: 17
Joined: Sat Jul 07, 2007 7:53 pm

VBRun Parameters Passed by Value or Reference

Post by MikeB941 » Sun Jan 22, 2012 8:59 pm

Macro Scheduler Pro 12.1.10

It appears that when calling a VBScript Subroutine using VBRun the parameters are passed by value? Is that correct?

Is there a way to pass the parameters by reference (i.e. &varname) such that changes to the variable WITHIN the VBScript subroutine are reflected outside the VBScript subroutine back in the Macro Scheduler main code?

I just need some "global" way to get a value back from a VBScript Subroutine and available to the main Macro Macro Scheduler code after return.

I'm having string parameter passing trouble trouble with DBEval (see http://www.mjtnet.com/forum/viewtopic.php?t=7178 ) or I'd use that.

Thanks very much for your help. Take Care... Mike.

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

Post by Marcus Tettmar » Mon Jan 23, 2012 11:12 am

No, you cannot pass Macro Scheduler variables by reference to VBScript.

But you can easily pass values out of functions or access VBScript variables.

E.g. if you just want to return one thing then use a Function:

Code: Select all

VBSTART
 Function MultBy10(input)
    MultBy10 = input * 10
 End Function
VBEND

VBEval>MultBy10(5),answer
MessageModal>answer
In this example the function returns a value and we get that value into the MacroScript variable called answer.

Now, what if you want to return lots of things. Well we could just set some global VBScript variables and access them:

Code: Select all

VBSTART
  'some global vars
  Dim x, y, z
  Function DoSomething(input)
    x = input * 10
    y = input * 5
    z = input + 100
    DoSomething = x + y + z
  End Function
VBEND

VBEval>DoSomething(4),result
VBEval>x,myX
VBEval>y,myY
VBEval>z,myZ

MessageModal>%result% %myX% %myY% %myZ%
see how as well as getting the function result from VBEval we can then also "evaluate" the VBScript variables. They have to be global in the VBScript because if they were only local to the function they'd have lost scope and no longer exist by the time we want to query them.

If you want to return a lot of values or don't know how many (e.g. an array) then ReDim a VBScript array that is declared globally to the VB block and then access it via 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?

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