NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Use VB Set keyword with Clone method?

I am using the TestStand API with Visual Basic 6.0 SP5. Is is necessary to use the Set keyword when calling the Clone method of a PropertyObject? i.e. which is correct:
Set thePropObj = existingPropObj.Clone("", 0)
or
thePropObj = existingPropObj.Clone("", 0)

Seems the Set keyword would be required, but I am
running into funny problems with this. I have a step
that I am trying to create a copy of. (The step contains a call to a LabVIEW VI.) If I omit the Set keyword, execution hangs at the call to Clone. If I include the Set keyword, all information present in the original PropertyObject doesn't seem to get copied to the new one. (Also, oddly enough, if I omit the set keyword, and the step calls a CVI function, everything seems to work
fine!)

Anyone have any advice?

Thanks in advance
D. LaFosse
0 Kudos
Message 1 of 2
(2,815 Views)
Hello LaFosse,

You need to use the Set keyword before the clone method statement. However, I have a couple of comments about the code you sent.

This is the code you sent:

' Start up the testStand engine
Dim theTS As TS.Engine
Set theTS = New TS.Engine

' OK, load in the sequence file I
' created. This sequence file
' contains nothing more than a call
' to a VI in the main stepgroup of
' the MainSequence.
Dim seqFile As SequenceFile
Set seqFile =
theTS.GetSequenceFile()

' get a handle to the MainSequence
Dim seq As Sequence
Set seq = seqFile.GetSequenceByName
("MainSequence")

' Get a handle to the step that calls
' the VI, and a property object for
' the step
Dim theStep As Step
Set theStep =
seq.GetStep(0, StepGroup_Main)
Dim theStepProp As PropertyObject
Set theStepProp =
theStep.AsPropertyObject

' Create another step. We will attempt
' to use Clone to fill in the
' properties of this step.
Dim theOtherStep As Step
Dim theOtherStepProp As PropertyObject
Set theOtherStep = theTS.NewStep("",
TS.StepType_Action)
Set theOtherStepProp =
theOtherStep.AsPropertyObject

' Call clone...this step will hang.
theOtherStepProp =
theStepProp.Clone("", 0)

Basically the problem is that you are not loading the TypePallete after creating the engine. You shoud include right after the Set theTS = New TS.Engine:

theTS.LoadTypePaletteFiles

This should avoid the crash.

Some Additional comments:

1. With VB you don't need to create property objects from other objects. All the classes, except the Engine Class, inherit from the Property Object Class. The following Code does the same thing, but without creating propertyobjects directly:

Sub MySub()

'Variable Declaration
Dim theTS As TS.Engine
Dim seqFile As SequenceFile
Dim seq As Sequence
Dim theStep As Step
Dim theOtherStep As Step

'Create the Engine
Set theTS = New TS.Engine

'Load the Types
theTS.LoadTypePaletteFiles

'Get Sequence File
Set seqFile = theTS.GetSequenceFile()

'Get Sequence
Set seq = seqFile.GetSequenceByName("MainSequence")

'Get Step
Set theStep = seq.GetStep(0, StepGroup_Main)

'Clone the Step
Set theOtherStep = theStep.Clone("", 0)

'Using the inheritance functionality
'gets the Step Status
'Notice that theOtherStep is not a PropertyObject
'and you can use all the properties and methods that
'applies to the PropertyObject Class to a Step class
'in this example

'Also, in VB when you are typing the statement, you
'will not see the PropertyObject Class properties and
'and Methods automatically if the variable is not a
'PropertyObject type. However, you can still use them
'as mentioned before

MsgBox (theOtherStep.GetValString("Result.Status", 0))

End Sub

2. When you create or modify sequence files programatically be carefull not to break the license Agreement. You need the development lisence when modifying sequences.

3. This piece of code is not completed, and you will need to shutdown the engine by the end.

4. Since you are not handling UI Messages, you will need to be carefull when loading sequences that have the SequenceFileLoad Callback. The engine posts UI Messages when executing this callback. Also when you shutdown the engine, UI Messages are posted. For both operations (Load Sequence and Shuutdown) you may prevent the engine from posting the message (You may check the options parameter for this two methods in TS Programmer Help.)

5. If you want to run a sequence, again you will need to incorporate in your code the UIMessage Handler part. (You may check the TS Programmer Help->Writing an Application Using the API->UI Messages). Otherwise it may hang since the engine posts UI Messages eventually.

Regards,

Roberto Piacentini
National Instruments
Applications Engineer
www.ni.com/support
0 Kudos
Message 2 of 2
(2,815 Views)