Hello,
I often use Basic automation to edit my programs. Most of the time, I need to add some commands in all programs used in the company. As that makes hundreds of programs, it is always a long job.
My problem is with marked sets.
In the shop the programs are used in "operator mode", so marked sets are mandatory. And if you add a command through Basic, it will not be markes for execution in the marked set.
Finally, I have found a solution I present here.
First, to access to marked sets through Basic :
You need to execute at least one command to really set the marked set
Now, loop on all marked sets to mark the new command :
Edit : CODE /CODE tags
I often use Basic automation to edit my programs. Most of the time, I need to add some commands in all programs used in the company. As that makes hundreds of programs, it is always a long job.
My problem is with marked sets.
In the shop the programs are used in "operator mode", so marked sets are mandatory. And if you add a command through Basic, it will not be markes for execution in the marked set.
Finally, I have found a solution I present here.
First, to access to marked sets through Basic :
Code:
Set pcpart = pcapp.PartPrograms.Open( _ "program.PRG", _ "Offline") Set cmds = pcpart.Commands cmds.InsertionPointAfter cmds(87) 'just an example pcpart.ClearExecutionMarkedSet pcpart.SetExecutionBlock pcpart.Commands(1), pcpart.Commands(2) pcpart.Execute ' add a command. here, variable assignement with nothing in it Set cmd = cmds.Add(ASSIGNMENT, True) cmd.PutText "MA_VAR", DEST_EXPR, 0 cmd.PutText "", SRC_EXPR, 0 cmd.Marked = True
Now, loop on all marked sets to mark the new command :
Code:
i = 0 res1 = "" retVal = pcpart.GetMarkedSetName(i, res) 'initialize with first marked set While res <> res1 pcpart.SetExecutionMarkedSet res pcpart.SetExecutionBlock pcpart.Commands(1), pcpart.Commands(2) pcpart.Execute Application.Wait Now + TimeValue("00:00:01") cmd.Marked = True i = i + 1 res1 = res retVal = pcpart.GetMarkedSetName(i, res) ' if no new marked set : res will not bne changed => loop end Wend
Comment