This example shows how to create a UserForm in the UserGlobals page and reference it from a picture for the purpose of data entry. Inserting run-time accessible forms in the User Globals page allows only one copy of the form on the system. This makes version control easier and minimizes the size of iFIX picture files.
This example uses a form that you create in User Globals. The following figure shows how it should appear in the run-time environment.
Data Entry Dialog Box
This example contains a UserForm frmListEntry and a module UGSubs, both of which are located in Project_User. The name of the picture is LISTENTRY1.GRF.
Example: Form Code
Option Explicit
Dim strDataSource As String
'Custom subroutine to pass DataSource and List items to form
Public Sub SetupTheData(DataSource As String, _
Optional Item1 As String, Optional Item2 As String, _
Optional Item3 As String, Optional Item4 As String, _
Optional Item5 As String, Optional Item6 As String)
'Get the data source and any passed-in items for the list.
'This example uses six items, but there is no limit.
strDataSource = DataSource
If Item1 <> "" Then EntryBox.AddItem Item1
If Item2 <> "" Then EntryBox.AddItem Item2
If Item3 <> "" Then EntryBox.AddItem Item3
If Item4 <> "" Then EntryBox.AddItem Item4
If Item5 <> "" Then EntryBox.AddItem Item5
If Item6 <> "" Then EntryBox.AddItem Item6
End Sub
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub OKButton_Click()
Dim DataObj As Object
On Error GoTo ErrorHandler
'Write the chosen value from the list to the tag.
Set DataObj = System.FindObject(strDataSource)
DataObj.Value = EntryBox.Value
Unload Me
Exit Sub
ErrorHandler:
MsgBox "Error " + Str(Err.Number) + " has occurred" _
+ Chr(10) + Chr(13) + Err.Description
End Sub
Example: Module Code
Option Explicit
'Declare the Form object.
'This must be in a Module to use the user-defined data type.
'The user-defined data type allows Quick Info and Auto
'Complete to work.
Public ListForm As frmListEntry
Public Sub GetListForm()
'Creates a new instance of the form.
Set ListForm = New frmListEntry
End Sub
Example: iFIX Object Code
Private Sub CommandButton1_Click()
On Error GoTo ErrorHandler
'Create an instance of the form.
UGSubs.GetListForm
'Pass in the tag to control and load the form list with
'choices. Use text or numbers as appropriate for the
'tag-field data type.
UGSubs.ListForm.SetupTheData _
"Fix32.BATCH1.BATCH-RECIPENAME.A_CV", _
"Off", "Low", "Medium", "High"
'Show the form.
UGSubs.ListForm.Show
Exit Sub
ErrorHandler:
HandleError
End Sub