Sign in to follow this  
Followers 0
BE

NA HMI - Update Dropdown Text from Global Subroutine

2 posts in this topic

Hi All,

I am in the process of creating VBA script to update several dropdown boxes on some customer NA Series HMI's. The main one they want to update is their supervisor drop down menu.

The main code I managed to get and modify from here :https://forums.mrplc.com/index.php?/topic/33282-read-an-array-of-strings-from-nj-to-na/

Sub DropDownBox_Update
    Dim List_obj As Object 
    Dim array(DropDown_ArrayCount_PLC) As String
    Dim x As Integer
    For x = 1 To DropDown_ArrayCount_PLC
        array(x) = DropDown_Array_Fixed_PLC(x)
    Next x
        array(0) = "Please Select"
    List_Obj = array
    DropDown0.SetItems(List_Obj)
    ArrayUpdateBool_PLC = True
    Run_Script_PLC = False
End Sub

The problem I have is that there are about 6-10 different supervisor drop downs in various pages on the HMI. Ideally I would like to run the script as a global script, with a reference to each drop down, instead of a page specific subroutine on each page. However when I change DropDown0.SetItems(List_Obj) to Page0.DropDown0.SetItems(List_Obj) as a global subroutine, Sysmac Studio tells me that 'Page0' is not declared, so it won't run.

Does anyone know if it is possible to call/reference an object on a specific page from a global subroutine? I am fairly new/inexperienced with the VBA side of things.

Omron Australia couldn't make it work when I spent 10min on the phone with them earlier. They are going to look into it and get back to me so I figured I would ask here too :-)

Share this post


Link to post
Share on other sites

Posted (edited)

Got a more detailed response back from Omron Australia, so figured I would post it here, along with what I ended up doing.

Omron: After having a look through the internal database and further information regarding VB code and NA HMI, it is not possible to reach objects from a global subroutine, only from local subroutines unfortunately.

So I can't do what I planned. Oh well, tried another tack, seeing if I could declare a script input/output variable (object type) in a global VBA script, that could then be referenced by a local subroutine. Didn't have any luck here either at my end, and Omron's feedback on this was as follows:

Omron: You can potentially pass an array to the local subroutine, but not a dropbox object as this is a combobox object, which I can't see the option to define it as a combobox, therefore when you try to set the items it will not work because it is not aware that there is a set of items allocated to this object.

 

Well, that exhausted all my ideas, besides copying the code as a subroutine in each page and having it run each time the page is displayed, which is what I ended up doing. Updated the clients PLC and HMI's, and I have a very happy customer. The final code I ended up with was as follows in case anyone is trying to do something similar in future. I changed it from the code in my first post due to some comments in this thread about the  "List_Obj = array" line.

Sub SupervisorDropDownBoxUpdate
    Dim List_obj(Supervisor_Names_Array_Count_OmronPLC) As Object 
    Dim x As Integer
    For x = 1 To Supervisor_Names_Array_Count_OmronPLC
        List_obj(x) = Supervisor_Names_Array_OmronPLC(x)
    Next x
        List_obj(0) = "Please Select Supervisor"
         DropDown0.SetItems(List_Obj)
End Sub


For reference:

  • The Supervisor_Names_Array_Count_OmronPLC is an INT variable, in my case I was using this to vary the qty of options in the drop down list so I didn't have any blanks.
  •  List_obj(0) = "Please Select Supervisor" - This just sets the 0 option in the list, with the array items starting at 1, as shown in the FOR loop above this line.
Edited by BE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0