Wildcards and VBA in Rockwell FactoryTalk View SE

I am very new to VBA (I did 3 weeks in 9th grade but about that). I am an industrial PLC programmer by trade, but one of my applications required me to unearth painful memories of 9th grade IT for a Rockwell FactoryTalk View SE SCADA system.

My application is a server that stores a graphic display and several clients that render those graphic displays. Depending on which client is being used, I want certain items to be visible or invisible to the user. I can do this in a basic sense, but I am wondering if there is a more efficient way. Here is the code as it stands:

Private Sub Display_AnimationStart()
Dim HostName As String
HostName = Environ$("computername")
Select Case HostName
    Case "CCSPE1X2"
        Elements.Item("VBAControl_X2Only").Visible = True
    Case "CCSPE1X3"
        Elements.Item("VBAControl_X3Only").Visible = True
    End Select
End Sub

      

It all works; I just group everything that should only be visible to the X2 client in a group called "VBAControl_X2Only" and so on. But this makes the graphics editor work with pain, as it displays fragments from all over the screen, stacked into one group, separated from the rest of the groups to which they really should belong. I figured it would be better to take them from one big group and just add each item in separate VBA code.

Then I thought, what if there is a way to use wildcards here? Thus, any item that should only be displayed on CCSPE1X2 I call "StartButton_X2Only" or "StopButton_X2Only" etc. Then I search for any object whose name ends with "X2Only" and makes it invisible.

Im representing something like:

Dim ElementName As String
        If Elements.Item("*").Name Like "*X2Only" Then
            ElementName = Elements.Item("*").Name
            Elements.Item(ElementName).Visible = True
        End If

      

It doesn't work (I really didn't expect it to be honest); when it hits If Elements.Item ("*") it gives error 91 - object variable or with not specified block variable.

Can anyone tell me how close I am to the sign? Or if this is not possible? I don't even know if there is a way to make it look for every item in the display, since this is not just an Excel spreadsheet where I could say it is looking for a column.

Thank!

+3


source to share


1 answer


You will need to iterate over all the individual items. Try something like this:



    For Each Item In Elements
        If Item.Name Like "*X2Only" Then
            Item.Visible = True
        End If
    Next Item

      

+3


source







All Articles