How to send an Array to VBScript

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

How to send an Array to VBScript

Post by billtubbs » Tue Dec 12, 2006 11:18 pm

I couldn't find any documentation on how to pass the contents of an array from Macroscript code to VBScript. The following post contains an explanation of how to get an array out of VBScript:

http://www.mjtnet.com/usergroup/viewtopic.php?t=1151

Is it also necessary to make a delimited string, and if so what's the easiest way to uncouple it in VBscript?

[ I am trying to send the contents of a Macroscript array to a database ]

Bill.

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 Dec 13, 2006 8:54 am

Since MacroScript arrays are not the same as VBScript arrays you'd need to populate each element one at a time. So you just need a loop that loops through your array, with a VBEVal statement inside assigning the value to the corresponding VBScript array element.

You don't need to "decouple" strings. VBScript wants them delimited. Just put quotes round them when you send into VBScript and VBScript handles the rest. If a string contains a quote char then double quote it. Use StringReplace to replace all occurrences of " with "".
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

Post by billtubbs » Wed Dec 13, 2006 8:11 pm

Thanks marcus

I ended up passing a string and using the VB split() command to assign t he values to an array. Here is the code if anyone is interested. It works OK for numbers and only for one-dimensional arrays I guess.

Code: Select all

VBSTART

Sub SendArray(DataText)

    Dim MyArray

    MyArray = Split(DataText, " ", -1, 1)
    MsgBox(MyArray(0) & ", " & MyArray(1) & ", ...")

End Sub

VBEND

VBRun>SendArray,15 20 25 30 35 40 45
[/code]

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