Excel VBA Coding Help: Add New Variables to Strategy


#1

I know this is too much to ask, but if you could help code automate adding new variables to PAC Strategy.

Did not have find time to do this.


On PAC Control Manual


Search for “CLI command” in manual:

Command Line syntax:
<PAC Control.exe> <strategy.idb> /av <variable type>;<variable name>;<description>;<initialization type>;<initial value>;[;<string width>][;<table length>]

<PAC Control.exe> = “C:\Program Files (x86)\Opto22\PAC Project 10.2\Control.pro.exe”
<strategy.idb> = “C:\Users\eugene\Groov EPICs\Strategies\sample.idb”
<variable type> =
INT32_VAR
INT64_VAR
FLOAT_VAR
STR_VAR
DNTMR_VAR
UPTMR_VAR
INT32_TBL
INT64_TBL
FLOAT_TBL
STR_TBL

<variable name> = nBlaBlaBla
<description> = " "
<initialization type> =
ON_DOWNLOAD
ON_RUN
PERSISTENT
<initial value> = 0 (for timers, enter a space, " " maybe)
[;<string width>][;<table length>]
= maybe [ ] means optional, takes number
for strings = ;15;99
for numerical table = ;99


On Excel


Filename: Strategy Add Variable Macro.xlsm
At cell A1: Command Path: C:\Program Files (x86)\Opto22\PAC Project 10.2\Control.pro.exe
At cell A2: Strategy Path: C:\Users\eugene\Groov EPICs\Strategies\sample.idb
Command Button: Execute

On Row 5. Enter header name as follows:
Variable type drop down | variable name | description | initialization type drop down | initial value | string width | table length


VBA code guidelines


dim CLI_Command as string
CLI_Command = Range("A1")
...etc

dim wsh as object
wsh = VBA.CreateObject("WScript.Shell")
dim waitOnReturn as boolean: waitOnReturn = True
dim windowstyle as integer: windowstyle = 1

for each row in row 5 until empty {

wsh.Run "cmd.exe /S /C" & CLI_Command & " " & strategy_name & .. so on.. & initial_value & , windowStyle, waitOnReturn

Application.Wait (Now + TimeValue("0:00:1")) 
}

or we could write a batch file and run manually:
at cell C3: Output filename = Batch_Add_Variables.bat


Output_Filename = "C:\some folder name\" & range("C3");

fnum = FreeFile()
Open Output_Filename for output as fnum
for each row {
Print #fnum, CLI_Command & Strategy_Name_var & so on .. & initial_value_variable
}
close #fnum

That is pretty much it :slight_smile:

I really do not have time to debug… :slight_smile: