Technical FAQs

Ask a Question

Example of mimic script to populate dropdown list with user and set selected user as Duty User in user roster

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 dropdown list can be populated with a list of ClearSCADA users and how a user can be selected from the list and be set as Duty User in a user roster.
Sub PopulateDropdownListExample
Dim frmComboBox, frmOKButton, frmCancelButton
Dim sqlUserLookupRows, sqlUserLookupRowsCount
Dim oSelectedUser, oComboArray()
Dim c,r
'Retrieve a list of all users from the database. This portion could be improved further by getting a list of users for a particular user roster
' instead of showing a list of all users
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
'This will be needed at the end to cross reference the selected row in the dropdown list with the actual users
ReDim oComboArray(sqlUserLookupRowsCount)
'Define the user roster object. In this example, the user roster object is called User Roster and is located in group Example and sub-group Set User Roster)
Set oUserRoster = Server.FindObject("Examples.Set User Roster.User Roster")
'Display a VB form
Form.Init "Please make a selection"
Form.AddGroupBox 0,0,100,8,""
Set frmComboBox = Form.AddComboBox(0,1)
'Populate the dropdown list with the list of users retrieved from the database earlier
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(60,5,"OK")
frmOKButton.Default = True
Set frmCancelButton = Form.AddPushButton(75,5,"Cancel")
'Pass the selected user when calling the SetDutyUser method. Note, the selected user has to be configured in the user roster this this part of the example to work.
oSelectedUser = oComboArray(frmComboBox.Selection)
msgbox oSelectedUser + " is selected"
oUserRoster.Interface.SetDutyUser oSelectedUser
End Sub
Was this helpful?
What can we do to improve the information ?