Reputation: 11
I want to change the code below, so that it executes the sas guide project (.egp) and changes the parameter value according to the values of the array. (The idea is to open the project, run to the value of the array (0), close the project; open the project, run to the value array (1); ... until the array (n)).
But it executes only for the first value of the array, not the sequence for the other values. What's the mistake?
I added the line (for t = 0 to UBound (id)) and put (Next) before app.Quit
Dim t
Dim id
id=Array("111111111","22222222","33333333")
'-----------------------------------
' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name
for t = 0 to UBound(id)
And at the end of the code
Next
app.Quit
The full code
Option Explicit
'----------------------------------------------------------------
'AutomationPrompts.vbs
'This example program demonstrates how to use the 4.2 SAS Enterprise Guide
'automation interface to access and modify the prompts for a project and a stored
'process within that project. The project is opened and the project prompt names
'and values are displayed to the user. Subsequently, the stored processes within
'the project are opened and their prompt names and values are then displayed.
'
'The prompt value for the stored process is changed to 'M' (for male), the project
'is saved then run.
'
'The project is called AutomationwithPrompts.egp and the prjName variable should be
'modified to reflect the location of this proejct on the machine that is running
'this script.
'----------------------------------------------------------------
'--------------
'Declare the variables that will be used in the program
'--------------
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm
Dim spList
Dim sp
Dim spParamList
Dim spParam
Dim spParamName
Dim spParamValue
Dim n
Dim i
Dim t
Dim id
id=Array("111111111","22222222","33333333")
'-----------------------------------
' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name
for t = 0 to UBound(id)
' Start the app and open the project
Set app = CreateObject("SASEGObjectModel.Application.8.1")
Set prjObject = app.Open(prjName,"")
'---------------------------------
'Begin processing the project
'---------------------------------
' Discover the parameters for the project
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."
' Get the default value from the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue
' Change the value of the parameter to 'M' and display the new value.
parm.Value = id(t)
WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value
'-------------------------------
'Begin processing the stored process
'-------------------------------
Set spList = prjObject.StoredProcessCollection
' Get the number of parameters for the store process
Wscript.Echo "StoredProcess has " & spList.Count & " parameters."
' Cycle through the list of stored processes and the parameters for each of them.
for n=0 to (spList.Count - 1)
Set sp = spList.Item(n)
' Get the list of parameters
Set spParamList = sp.Parameters
' Process each stored process parameter
for i=0 to (spParamList.Count - 1)
Set spParam = spParamList.Item(i)
' Get the name and default value for the parameter
spParamName = spParam.Name
spParamValue = spParam.DefaultValue
' Display the parameter information to the user
WScript.Echo spParamName & " parameter has default value of " & spParamValue
' Change the value of the parameter
spParam.Value = id(t)
' Display the modified value
WScript.Echo spParamName & " parameter has been set to value of " & spParam.Value
' Save the project with the updated stored process
prjObject.Save
Next
Next
' Run the new project
prjObject.Run
' Make sure the project is saved after it has been run.
prjObject.Save
' Close the project and application.
prjObject.Close
Next
app.Quit
Upvotes: 0
Views: 525
Reputation: 11
I got it, the final code is below.
Option Explicit
'--------------
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm
Dim n
Dim i
Dim t
Dim id
id=Array("111111111","22222222","33333333")
'-----------------------------------
' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name
' Start the app and open the project
Set app = CreateObject("SASEGObjectModel.Application.8.1")
Set prjObject = app.Open(prjName,"")
'---------------------------------
'Begin processing the project
'---------------------------------
for t = 0 to UBound(id)
' Discover the parameters for the project
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."
' Get the default value from the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue
' Change the value of the parameter and display the new value.
parm.Value = id(t)
WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value
' Run the new project
prjObject.Run
WScript.Sleep 5000
Next
' Make sure the project is saved after it has been run.
prjObject.Save
' Close the project and application.
prjObject.Close
app.Quit
Upvotes: 1