#1
|
|||
|
|||
Using VBScript arrays
I want to use VBT to automate software deployments at the office. There are roughly 10 servers I deploy to and they’re split up into two batches. I’ve created arrays to access each server by name and I’d like to access the array variable in VBT. My project in its simple form looks like this:
Foundry (Group) Initialize Batch1 Variables (VBScript) Run Loop (Group Do Stuff Here Do More Stuff Here Increment Counter So the Foundry group initializes some variables and defines an array. The initialize script looks like this. Dim Batch1(5) Batch1(0) = "order1" Batch1(1) = "order2" Batch1(2) = "product5" Batch1(3) = "product6" Batch1(4) = "orderadmin9" Application.Macros(vbldTemporary).Add "SERVER_NUMBER", "0" 'Application.Macros(vbldTemporary).Add "SERVER_ARRAY", Batch1 Application.Macros(vbldTemporary).Add "TOTAL_BATCH1", UBound(Batch1) SERVER_NUMBER is a counter that simply defines how many iterations to run. I define it as 0 here because the first element in the array is always 0. SERVER_ARRAY, which is commented out is where I’d like to pass the array from the VBScript to VisualBuildTool. TOTAL_BATCH1 is just the number of the highest element in the array. What I want to happen is in the loop, certain actions will be performed on %SERVER_ARRAY%(%SERVER_NUMBER%) This should equate to Batch1(0)…(Batch1(4) But I get errors when I try to move the array over into VBT. Any help is appreciated. Last edited by gdanko; 05-27-2003 at 02:51 PM. |
#2
|
|||
|
|||
I think you need to turn the problem inside out. Store the array as a VBP macro and use a bit of script to extract the elements one at a time, perhaps to another VBP macro.
In similar situations I use strings of comma delimited elements as an "array" and have a script function that pops the first element off the list. |
#3
|
|||
|
|||
Got any examples on how to store the array as a VBP array? Until hearing from you I will experiment.
|
#4
|
|||
|
|||
Script variables do not persist outside of a Run Script step. One way to accomplish this would be to put your generic steps into a subroutine (on the Subroutine Steps or Global Subroutine Steps tab) and add one Subroutine Call step for each server in the Project Steps, passing the dynamic values for the subroutine on the Parameters tab. See the Advanced.bld or VisBuildPro.bld samples.
If you wanted to read the list of servers more dynamically (for instance, from a file), the Misc.bld sample ('Repeat for file contents' group) demonstrates how you can load a list of values into a temporary macro, and then loop over the macro, extracting each filename (using the vbld_AddDelimValue/vbld_NextDelimValue system script functions) and processing each one. |
#5
|
|||
|
|||
Every other variable comes through except the one where I try to pass the array. It errors out because I am trying to pass an array. If I assign any value, it works. I can send you a copy of the project if that helps.
|
#6
|
|||
|
|||
I don't want to be able to access the VBS array Batch1() directly.
In this example I was able to assign the results of the VBS expression UBound(Batch1) to the VBP TOTAL_BATCH1. This works. Application.Macros(vbldTemporary).Add "TOTAL_BATCH1", UBound(Batch1) In VBS I can do something like this: dim Array1(3) Array1(0) = "Blah" Array1(1) = "Foo" Array1(2) = "Fubar" ABC123 = Array1 MsgBox ABC123(2) This code will give me a msgbox with "Fubar" in it. I am saying, this array in VBS is equal to this array in VBS. I was able to pass an VBS variable to a VBP variable. I want to be able to pass my VBS array to VBP so it can be used. The PDF documentation isn't of much help here. Last edited by gdanko; 05-27-2003 at 05:37 PM. |
#7
|
|||
|
|||
problem solved
|
#8
|
|||
|
|||
Out of interest, and for the edification of others who may have a similar problem, how do you solve it?
|
#9
|
|||
|
|||
The first step of my loop determines the server name this way.
Dim Batch1(3) Batch1(0) = "WWW6" Batch1(1) = "WWW7" Batch1(2) = "WWW8" Application.Macros(vbldTemporary).Add "SERVER", Batch1(%COUNTER%) The counter is increased with each iteration, so the current server name is set approriately. I am now configuring it to read an .ini file for the number of servers and server names. |
|
|