FactoryTalk View SE looping through ActiveX controls

Zlinger

Member
Join Date
Mar 2014
Location
AZ
Posts
36
I've got several ListBoxes that I want to perform the same function on. From my searches, you can accomplish this in VBA by using a FOR loop, but only on the controls within a form. Rockwell knoweldgebase recommends to avoid using forms at all costs.

I've tried using a FOR loop on the ListBoxes in Me.ActiveDisplay, and I've also tried creating a group of my ListBoxes, exposing it to VBA, and trying a FOR loop on Me.MyListBoxGroup but the error is always "Object doesn't support this property or method."

Anyone ever do this or is it impossible without a form?
 
Yes, you probably can... define a variable as an element, say objElm, then do a loop for each objElm in activedisplay.elements. All of the list boxes have to be exposed to VBA control. You can look at objElm.name to decide which list Box you are on; it helps to have them named consistently in Object Explorer.

Give it a shot, I’ll try to post some of my vba tomorrow. There might be some trick if the objects are nested.
 
Here I'm just referencing the list box (ComboBox) directly:

in the ThisDisplay module
Call LoadTapRcv(Me.cmbTapRcv1, 1, 7, 1)

then the subroutine:

Private Sub LoadTapRcv(byval cmbCurr as MSForms.ComboBox, dblStart as double, dblEnd as Double, dblIncr as double)
on error goto proc_exit

Dim dblCurr as double

with cmbCurr
.Clear
for dblcurr = dblstart to dblend step dblIncr
.AddItem dblcurr
next dblcurr
.ListRows = .Listcount
end with

Proc_Exit:

exit sub

end sub

Another one, finding elements by name to load the list:

Dim elmCurr As DisplayClient.Element

Dim arrReasons As Variant

Dim intRow As Integer
Dim intCol As Integer

arrReasons = Array(" ", "Tap", "Burn", "Matte", "Cleaning", _
"Running", "Spill", "Vent", "Crane", "Slag")

For intRow = 1 To DispTapRows
For intCol = 1 To 3
Set elmCurr = Me.FindElement("cmbReason" & Format(intRow, "00") & CStr(intCol))
Call LoadDelayReason(elmCurr, arrReasons, intRow, intCol)
Next intCol
Next intRow


The loaddelayreason routine is just a variant on the first one. With the consistently named objects on the display, I can easily loop through and change all the controls I want. I misremembered my code, I ended up referencing all elements directly. I did have a recursive module to find the element, didn't need it:

Public Function GetElement(ByVal elmBase As DisplayClient.Elements, ByVal strCtl As String) As DisplayClient.Element

Dim elmCurr As Object

For Each elmCurr In elmBase
If TypeName(elmCurr) = "IGroup" Then
Set GetElement = GetElement(elmCurr.Elements, strCtl)
Else
If elmCurr.Name = strCtl Then
Set GetElement = elmCurr
End If
End If
If Not GetElement Is Nothing Then
Exit For
End If
Next elmCurr

End Function

You would call it as:

Set elmNeeded = GetElement(ThisDisplay.Elements, "lstMyList")

and it would return the lstMyList object into elmNeeded.
 
Art, thanks for your help. Fellow Arizonan here, by the way. That last bit where you use the function is similar to what I was attempting. I tried what you suggested and defined a function then called the function, but I still get the "Object doesn't support this property or method" error, and I'm not sure why.
 
If you step through the program using the F8 key, which line is it balking at? If you have your display client configured for debugging; a separate debug window will pop up showing the VBA, probably stopped right where you are getting the error.
 

Similar Topics

Hello, We recently upgraded our control server to a newer model. After the transition we are experiencing issues with our trend graphs to where...
Replies
1
Views
17
Hi, I wanted to ask is there a way to have a visibility expression use the IP address of the HMI (Dynics, not PV) to show certain elements? The...
Replies
3
Views
168
This is admittedly a pretty obscure problem, but maybe someone else has run into it, or at least something similar. For reasons I won't get into...
Replies
3
Views
105
Hey everyone and anyone that can lend a helping hand. I have a project that I am being asked to add some animations of Solidworks or "3D" models...
Replies
9
Views
301
I can't seem to get the Panel View Plus 7 standard edition to downgrade to V_11, when I check the AB downloads and compatibility websites for this...
Replies
1
Views
123
Back
Top Bottom