Browse FAQs

Example of mimic script that populates a Combo Box

Published date: 14 May 2019

This sample program is intended to demonstrate one or more programming functions or methods and is presented as programming example only. Schneider Electric assumes no liability for the use or application of this example program or any portion thereof.

This example shows how a ComboBox may be populated in ClearSCADA. The example also shows how a selection can be made from the populated ComboBox. It is done by populating an array at the same time as populating the ComboBox where the entries in the ComboBox match those of the array. When an entry is selected from the ComboBox the same entry is referenced to in the array and a variable is set.

Sub ShowForm

Dim frmComboBox, frmOKButton
Dim sqlUserLookupRows, sqlUserLookupRowsCount
Dim oSelectedUser, oComboArray()
Dim c,r

'Get a list of users from the database.
Set sqlUserLookup = Server.Query("SELECT FullName FROM CDBUSER")
sqlUserLookupRowsCount = sqlUserLookup.RowCount

'Set size of the array to match the number of users returned by the above SQL query
ReDim oComboArray(sqlUserLookupRowsCount)

'Build a VB form
Form.Init "Please make a selection"
Form.AddGroupBox 0,0,100,8,""
Set frmComboBox = Form.AddComboBox(10,1)

'Populate the ComboBox with the list of users retrieved
If Not(sqlUserLookup.Error) Then

    sqlUserLookupRows = sqlUserLookup.Rows
    sqlUserLookupColumns = sqlUserLookup.ColumnNames

    For r = 0 To (sqlUserLookup.RowCount - 1)
        For c = 0 To (sqlUserLookup.ColumnCount - 1)
            oComboArray(r) = sqlUserLookupRows(r,0)
    Msgbox sqlUserLookup.ErrorMessage, vbCritical + vbOKOnly, "Error in SQL Command"
End If

frmComboBox.Selection = 1
Set frmOKButton = Form.AddPushButton(40,5,"OK")
frmOKButton.Default = True

'Store the selected user in oSelectedUser and display it in a message
oSelectedUser = oComboArray(frmComboBox.Selection)
msgbox "The selected user is: " + oSelectedUser 

End Sub

Was this helpful?

What can we do to improve the information ?

Can't find what you are looking for?

Reach out to our customer care team to receive information on technical support, assistance for complaints and more.