08-22-2011 04:40 PM
I've built a GUI in the "View" pane that acts as a large table of contents. At the top of the GUI there is a list box that I would like to populate dynamically with the channel group names loaded in my data portal (internal data). I cannot seem to generate the code necessary to do this. Currently, I am using a ListBox. Should I be using an EnumListBox instead?
The purpose of the listbox is to allow for quick loading of the data that is to be analyzed into multiple sheets (also in the "View" pane) for side by side comparison rather than having to drag and drop data into each individual sheet.
Any help would be much appreciated,
Thanks,
~Nathan
Attached is a screenshot of the GUI hopefully it helps.
Solved! Go to Solution.
08-22-2011 04:50 PM
Currently my code looks like this:
Dim listNum, Names
for listNum = 1 to GroupCount
Set Names = GroupName(listNum)
selectData.Items.Add(Names)
next
The error I keep receiving occurs where I try to "Set Names = GroupName(ListNum)" and is an "Object Required: '[string: "filename"]'
where filename refers to my particular channel group name.
08-23-2011 08:52 AM
Hey Nathan -
Have we met yet? Don't think I recall seeing you post on the DIAdem forums thus far (nor do I remember meeting someone named Nathan in person recently). Welcome to the DIAdem forums!
There's a few things you need to alter about your code snippet -
- The reason you're getting the error "Object Required: '[string: "filename"]' is because the Set command expects that the right side of an expression returns an Object (that you set your variable to). In your case, you're returning a string (the name of a Group), not an object. Simply remove the Set command.
- The ListBox.Items.Add() method requires two parameters - the first is the text of the item to insert in the list, and the second is a value to assign to that item (which you should make unique).
Therefore, to most directly map your code snippet to working code, use the following:
Dim listNum, Names
FOR listNum = 1 TO GroupCount
Names = GroupName(listNum)
Call selectData.Items.Add(Names, listNum)
NEXT
Note that you can also use object oriented programming with the Data object representing the Data Portal, if it's easier for you to avoid remembering DIAdem variables such as GroupCount and GroupName (it is for me):
Dim listNum FOR listNum = 1 TO Data.Root.ChannelGroups.Count Call selectData.Items.Add(Data.Root.ChannelGroups(listNum).Name, listNum) NEXT
Your project is looking great - let us know how we can continue to help and keep us updated!
08-23-2011 09:51 AM
Hi Derrick,
We just recently acquired DIAdem at work. We're making the transition from Excel data processing and analysis to something more powerful, ergo DIAdem. Our colleagues in Germany have been using it for quite some time now and we decided to give it a try for uniformity's sake. Thanks for the help regarding this issue. My VB knowledge is very limited. I decided to use the object oriented version and it worked perfectly.
~Nathan
01-08-2013 09:38 AM
Hello,
I got a question about the code you write:
Dim listNum, Names
FOR listNum = 1 TO GroupCount
Names = GroupName(listNum)
Call selectData.Items.Add(Names, listNum)
NEXT
What is the "selectData" in this case?
Variable of the listbox?
My purpose is to get all my groups name in a list box
Thanks and happy new year 😉
Fred
01-09-2013 01:50 PM
Hi Fred,
"SelectData" in that code is the name of the ListBox control in the SUDialog. It functions in the SUDialog callback code like an object variable, but it's actually a ListBox object.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-10-2013 07:13 AM - edited 01-10-2013 07:18 AM
Hello,
Thanks it works now 🙂
I got another problems
I have 2 listbox, one display all the groups names (at eventinitialize), the other should display the channels the selected group from the first listbox.
So at first I display all groups in ListBox1
Sub Select_Groups_EventInitialize(ByRef This) 'Created Event Handler Dim listNum, Names FOR listNum = 1 TO GroupCount Names = GroupName(listNum) Call Select_Groups.Items.Add(Names, listNum) NEXT group_selected = 1 End Sub
Then I made a oneclickevent on the first listbox which refresh the second box.
Sub Select_Groups_EventMouseDown(ByRef This, Button, Shift, X, Y) 'Created Event Handler call Select_Channels.Refresh End Sub
When I refresh the secund box, it find all the channels in a group this way:
I begin at the first group (Index_Group) and I count all channels in it
I Increment the group number and I add all the channel to the previous number (Final_Channel_Number)
and this until I reach the selectioned_group
Then I know the channel number begin in the selectioned_group and the channel end number by adding the number of channels in this group
Sub Select_Channels_EventRefresh(ByRef This) 'Created Event Handler Dim Index_Group,Final_Channel_Number Index_Group=1 Final_Channel_Number=0 If(group_selected>1) Then Do Final_Channel_Number = Final_Channel_Number + GroupChncount(Index_Group) Index_Group = Index_Group + 1 Loop Until(Index_Group >= group_selected) End If
I display these channels into the listbox2
Dim listNum2, Names2 Call Select_Channels.Items.RemoveAll FOR listNum2 = Final_Channel_Number+1 TO Final_Channel_Number+GroupChncount(group_selected) Names2 = ChnName(listNum2) Call Select_Channels.Items.Add(Names2, listNum2) NEXT End Sub
My questions are:
Why do I have to click 3 times in the Listbox1 to get my values in the lisbox2?
Is there a easier way of getting the channels begins and end number of a specific group?
Thanks for support 🙂
Fred
01-11-2013 04:07 PM
Hi Fred,
I am not sure why you were having to click 3 times to update the listbox, but I was not able to replicate this behavior. I was able to get a Dialog working to properly display the channels in a group by handling the EventChange event from the first listbox. In this handler, I updated the group_selected variable and called the refresh function of the second listbox.
Sub Select_Groups_EventChange(ByRef This) 'Created Event Handler group_selected = Select_Groups.Selection call Select_Channels.Refresh End Sub
I seems to me that EventMouseDown catches all mouse clicks in the Dialog, not just clicks on the listbox. Using EventChange, we will run the code everytime the selection is changed.
Your method of finding the begining and ends of the groups is perfectly viable as long as you can follow the logic of it. You could change the code to iterate through the groups and index them individually rather than collectively, but your current implementation seems to be working.
I have attached the Dialog which I created for you to reference. I tested it in DIAdem 2012. Hope this helps.
01-14-2013 06:04 AM
The problem disapear with eventchange, thanks 😉
10-22-2020 08:34 AM
Hi,
I have tried to use this code in DIAdem 2019 and keep getting the message Object required: "
Dim listNum, Names, selectData
FOR listNum = 1 TO GroupCount
Names = GroupName(listNum)
Call selectData.Items.Add(Names, listNum)
NEXT
Call MsgBoxDisp (selectData)
Anyone got any ideas?
Thanks,
Hannah