Andy_P Posted July 28, 2017 Report Posted July 28, 2017 I have an array of 1000 strings in an NJ controller, and I wish to read them into an NA HMI. To do this at the moment I am using Array.Copy within some vb code, but this seems to hang the screen as it takes way too long, if it ever completes at all. i.e. Array.Copy(NJ_array, NA_array, 1000) also, the docs for Array.Copy state that the destination array needs to be greater in size than the source array, which seems bizarre. Any recommendations on how to do this more efficiently? Quote
innoaloe Posted July 29, 2017 Report Posted July 29, 2017 Why do you need to copy the Strings? Why not just use the Variable Map in NA to get the values of the said Strings inside NJ? Quote
Andy_P Posted July 29, 2017 Author Report Posted July 29, 2017 I need to read them all in at once, and this way also takes a very long time. I am trying to populate a ListBox with the string data. Quote
innoaloe Posted July 30, 2017 Report Posted July 30, 2017 Quote i.e. Array.Copy(NJ_array, NA_array, 1000) Looking at this you clearly had to map your NJ String arrays into that NJ_array variable. You already have the updated list of those strings, so I don't understand why you need to copy them again to another string array... Quote also, the docs for Array.Copy state that the destination array needs to be greater in size than the source array, which seems bizarre. All Copy/Paste process eventually will use an indexing process with some kind of "for loop" inside it. I doubt the variables are being copied all at once. The size difference might have something to do with the "for loop" implementation. Quote I am trying to populate a ListBox with the string data. Unfortunately you cannot change the Text inside ListBox object dynamically. Same goes for ComboBox/DropDown. There is no way to do so in NA. It's kind of suck, eventhough the IDE utilizes Visual Basic, the functionality is very limited. Quote
Andy_P Posted July 30, 2017 Author Report Posted July 30, 2017 19 hours ago, innoaloe said: Unfortunately you cannot change the Text inside ListBox object dynamically. Same goes for ComboBox/DropDown. There is no way to do so in NA. It's kind of suck, eventhough the IDE utilizes Visual Basic, the functionality is very limited. Yes you can. I am doing it by: ListBox0.SetItems(arrayOfObjects) The array has to be an array of Objects, (and not strings, integers, etc.) because that is all the Compact .NET Framework in the NA supports. Quote
chelton Posted July 31, 2017 Report Posted July 31, 2017 What is calling the array.copy sub? Can you copy the array in the background before calling the list box? Quote
innoaloe Posted July 31, 2017 Report Posted July 31, 2017 18 hours ago, Andy_P said: Yes you can. I am doing it by: ListBox0.SetItems(arrayOfObjects) The array has to be an array of Objects, (and not strings, integers, etc.) because that is all the Compact .NET Framework in the NA supports. Weird, because I cannot find that SetItems function anywhere in a ListBox component, even on the latest NA firmware version (1.08). Can you perhaps post a screenshot when the Intellisense shows this function? Regarding changing type to Object instead of String, wouldn't CType function work? It is used to convert / cast types without copying it to a new variable Quote
Andy_P Posted July 31, 2017 Author Report Posted July 31, 2017 Intellisense doesn't show it, but trust me, it is there and it works. This is a bug in the NA/Sysmac Studio software in my opinion. This is not the only function that is missing either. Omron need to improve this. Quote
innoaloe Posted August 1, 2017 Report Posted August 1, 2017 Well... that's definitely annoying. Gonna try it this afternoon, thanks. Quote
Andy_P Posted August 4, 2017 Author Report Posted August 4, 2017 I couldn't find a solution to this, so I have moved all the strings from retained memory in the NJ into retained memory in the NA. This works, as the NA can now For..Next loop through internal memory instead of reading each one from the NJ. However, this means I now have a bit of a disconnect between the data stored in the NJ and what is now stored in the NA. This is a bit annoying, but it is a solution of sorts for my application at present. Quote
chelton Posted August 4, 2017 Report Posted August 4, 2017 4 hours ago, Andy_P said: I couldn't find a solution to this, so I have moved all the strings from retained memory in the NJ into retained memory in the NA. This works, as the NA can now For..Next loop through internal memory instead of reading each one from the NJ. However, this means I now have a bit of a disconnect between the data stored in the NJ and what is now stored in the NA. This is a bit annoying, but it is a solution of sorts for my application at present. my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub; Sub ListBox_Update Dim List_obj As Object Dim array(100) As String Dim x As Integer For x = 0 To 99 array(x) = ListItems(x) Next x List_Obj = array listbox0.SetItems(List_Obj) End Sub Haven't tried with a larger array though. Quote
adept Posted November 9, 2021 Report Posted November 9, 2021 I know it is an old thread, I am glad I found it though. I like Chelton's solution for dynamic text display Does anyone have a solution to increment the values for each list item entry? It feels quite tedious to do it for 100 items in a list. I tried populating the list with excel an past it but it does not work. Quote
Stefan009 Posted December 13, 2021 Report Posted December 13, 2021 On 04/08/2017 at 9:20 AM, chelton said: my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub; Sub ListBox_Update Dim List_obj As Object Dim array(100) As String Dim x As Integer For x = 0 To 99 array(x) = ListItems(x) Next x List_Obj = array listbox0.SetItems(List_Obj) End Sub Haven't tried with a larger array though. Hi, 4 years later. Is it possible to have this multi dimensional? The combodrop list has a text and a value column when you enter it manually, is it possible programmatically add both those this way? Quote
David Antunes Posted December 22, 2021 Report Posted December 22, 2021 On 04/08/2017 at 8:20 AM, chelton said: my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub; Sub ListBox_Update Dim List_obj As Object Dim array(100) As String Dim x As Integer For x = 0 To 99 array(x) = ListItems(x) Next x List_Obj = array listbox0.SetItems(List_Obj) End Sub Haven't tried with a larger array though. Hello Does anybody got this running on the HMI? Because I can run it with no issues at all in the Simulation Mode in Sysmac Studio, but when I download the project to the HMI, as soon as I call the subroutine, it throws me an exception. "SafeArrayTypeMismatchException is thrown at CallMethod. E_SYS_999: 0x80131533" I could isolate that what is throwing the exception is the following instruction: List_Obj = array because is trying to assign an array of strings to an Object. Sub ListBox_Update() Dim List_obj As Object Dim array(6) As String Dim i As Integer For i = 1 To 5 array(i) = UserList(i) Next i List_Obj = array UsersListBox.SetItems(List_Obj) End Sub Quote
Stefan009 Posted December 22, 2021 Report Posted December 22, 2021 I have a similar function based on that code. This reads from a array in the plc Sub AddFromPLC() Do Until bHMI_UpdateEdit = False Loop Dim sPLC(99) As Object 'sPLC = zHMI_DesignRecipes.DesignName Dim i As Integer = 0 Dim l As Integer = 0 Dim iCount As Integer = 0 For i = 0 To 99 sPLC(i) = zHMI_DesignRecipes.DesignName(i) ' + " " + (i+1).ToString Next DropDown1.SetItems(sPLC) End Sub Sub UpdateIndexInfo() Dim sValue As String = "" sValue = DropDown1.SelectedIndex bHMI_UpdateEdit = True Label2.Text = sValue bHMI_DesignEditIndex =sValue End Sub Quote
David Antunes Posted December 23, 2021 Report Posted December 23, 2021 Hello Stefan009! I didn't know I could copy String values directly into objects! It works! I leave the code bellow: Sub ListBox_Update() 'Limit the Qty of Users to a valid range If (QtyUsers < 0) Then QtyUsers = 0 End If If (QtyUsers > 20) Then QtyUsers = 20 End If Dim List_obj(QtyUsers) As Object Dim i As Integer For i = 1 To QtyUsers List_obj(i) = UserList(i) 'UserList from PLC Next i List_obj(0) = "Select User:" UsersListBox.SetItems(List_Obj) UsersListBox.fontsize = 25 SELECTED_USER = 0 End Sub Thank you! And a Merry Christmas! Quote
Zeev Posted October 7, 2024 Report Posted October 7, 2024 Hello All, Have a similar error while trying to read user roles and put them into listbox Dim array(100) As String Sub GetAllRoles array= System.Linq.Enumerable.ToArray(_Hmi_s_Roles()) RolesBox.SetItems(array) End Sub Does anyone know workaround for it? Thank you Quote
Zeev Posted October 7, 2024 Report Posted October 7, 2024 Hello Photovoltaic, It's ok I want to get a list of all available roles so I will give it as a list to user so he can create a new username with one of roles. Problem is that I couldn't do it directly I read this topic and found out something that partly works Dim array(100) As String Dim List_obj(100) As Object Dim x As Integer Sub ShowRoles array = System.Linq.Enumerable.ToArray(_Hmi_s_Roles()) For x=0 To array.Length List_obj(x) = array(x) Next x DropDownRole.SetItems(List_obj) End Sub the problem is here " array.Length" , it gives me an IndexOutOfRange error. Is there a way to figure out what indexes in array filled with data? Thank you Quote
BE Posted October 22, 2024 Report Posted October 22, 2024 I make some comments in this thread that might be useful for you, including my final code. My guess is that array.Length isn't a integer variable or is too large. What is the value of array.length? It looks like a structure member or something trying to call the length of an array that hasn't been defined, I can't really tell without more information. When I did mine, I had a standard integer variable that advised the total qty of non-null values in my PLC array (there was code to make sure all the null values were at the end of the array), and then this variable was subsequently used for the array of obj in the HMI. This way the list box didn't show a heap of blank entries. https://forums.mrplc.com/index.php?/topic/44133-na-hmi-update-dropdown-text-from-global-subroutine/ Quote
Francesco.corradin Posted January 21 Report Posted January 21 Using the ‘Data Display’ object, it is possible to indicate the variable to be read by means of an expression. Suppose we have in the PLC an array ‘ABC[0..999] of INT’ and in the HMI an internal variable ‘X’ which I will use as a pointer. On a display page, I will insert 10 data displays, in which I will enter the following values in ‘Expression DataDisplay_1 ABC(X) DataDisplay_2 ABC(X+1) ... DataDisplay_10 ABC(X+9) By varying the value of X from 0 to 990 (999-10) via a ‘Slider’ object, I will be able to display all the registers in my array. The panel will be very fast and dynamic. Quote
BE Posted January 21 Report Posted January 21 8 hours ago, Francesco.corradin said: Using the ‘Data Display’ object, it is possible to indicate the variable to be read by means of an expression. Suppose we have in the PLC an array ‘ABC[0..999] of INT’ and in the HMI an internal variable ‘X’ which I will use as a pointer. On a display page, I will insert 10 data displays, in which I will enter the following values in ‘Expression DataDisplay_1 ABC(X) DataDisplay_2 ABC(X+1) ... DataDisplay_10 ABC(X+9) By varying the value of X from 0 to 990 (999-10) via a ‘Slider’ object, I will be able to display all the registers in my array. The panel will be very fast and dynamic. One of the admins might want to move this to a new thread. If I had to do that, I would create an additional array (0-9) in the PLC that your Data Displays reference. Then write some code to "Move" the respective values from your large array to this new array based on the integer X. This would be easy enough to do with a FOR loop, or a series of move functions. That way there is no VBA, the HMI just reads the values from the PLC. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.