1. Navigate to the SCRIPT Panel and select
File >> New VBS.
- Save the VB Script as "Adding Variables to File Name.VBS".
2. Define the variables that will be used in the VB Script.
- This example utilises two variables: sPathDocuments and selectedFrequency.
- sPathDocuments will store the path to the current script file, and selectedFrequency is the variable that will be appended to the TDM file name.
- To define these variables, enter the following script:
Call GlobalDim("sPathDocuments")
Call GlobalDim("selectedFrequency")
sPathDocuments = CurrentScriptPath
selectedFrequency = 12. Optional: Remove any data currently inside the
Data Portal with the following command.
Call Data.Root.Clear()3. Generate a
User Dialog Box that allows users to specify the value of a variable. For this example, the user will define the value for
selectedFrequency.
- From the top toolbar, select Edit >> Create Dialog Box.
- In the DIAdem Dialog Editor window, drag and drop objects from the Control bar to the Dialog Box. This example utilises a Numerical EditBox and OK, Cancel Control, as shown.
- Click on the Dialog Box to select it. From the Properties Window, select the three ellipses next to the Variables property.
- In the DIAdem Variables window, select New Entry...
- Specify the name of your variable as the Name and Variant as the Type. Click OK to save the configuration. Note: In this example, the variable name is selectedFrequency. This property is case sensitive, so ensure that it matches your VB Script variable exactly.
- The new variable should appear as follows:
- Click on the Numerical EditBox to select it.
- From the Properties window, click the drop-down arrow next to the Variables property and choose the newly created variable. This maps the VB Script variable to the Dialog Box, allowing users to manipulate the value of VB Script variables.
- Save the Dialog Box as "FrequencyDialog.SUD" in the same directory as your VB Script.
4. Call the Dialog Box in your VB Script using
SUDDlgShow, as demonstrated below. Here, "FrequencyDialog.sud" should match the name of your SUD file.
Call SUDDlgShow("Dlg1", "FrequencyDialog.sud")5. Generate a signal with the selected Dialog Box frequency.
- Use the ChnGenSignal command to generate a signal. This example generates a Sine Wave and takes selectedFrequency as the fifth parameter.
- Use the Val() function to convert the variable to a numeric data type.
Set ChnResult = ChnGenSignal("Sine", 1024, 100, "/GeneratedSignalChannel", Val(selectedFrequency), 30, 0, 0, "s", "V", 50)6. Save the generated data as a TDM file and append the variable to the file name.
- Use the DataFileSave to save the TDM file.
- The first parameter is the full path of the file. Specify the path as sPathDocuments & "GenerateSine_" & str(selectedFrequency) & "Hz.TDM". This will save the TDM file in the same location as the VB Script with the frequency appended to the end of the name.
- Note: It is important to use the str() function to convert the variable to a string data type first.
Call DataFileSave(sPathDocuments &"GenerateSine_" & str(selectedFrequency) & "Hz.TDM", "TDM", True)