Author Topic: Populate combobox with PartNumbers from PLC  (Read 1778 times)

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Populate combobox with PartNumbers from PLC
« on: July 12, 2016, 03:51:51 PM »
I would like to populate a combobox with part numbers from PLC.  The part numbers are UDT like below:

Partnum[0].PartNumber = '1234'                          'string
Partnum[1].PartNumber = '2345'                          'string
.....

Is there a good way that is similar to getting Com ports into combobox

Code: [Select]
myPort = IO.Ports.SerialPort.GetPortNames()       
 For i = 0 To UBound(myPort)
        cmbPort.Items.Add(myPort(i))
 Next
 cmbPort.Text = cmbPort.Items.Item(0)   
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Populate combobox with PartNumbers from PLC
« Reply #1 on: July 12, 2016, 05:57:50 PM »
This is how I populate a combobox with ports, which is essentially the same as you have in your post:
Code: [Select]
        '* Retreive available ports and add to combo box
        Dim ports() As String = System.IO.Ports.SerialPort.GetPortNames()
        Array.Sort(ports)
        For i As Integer = 0 To ports.Length - 1
            PortName.Items.Add(ports(i))
        Next
        PortName.Text = ports(0)


Populating a ComboBox with values from a PLC would be very similar:

Code: [Select]
ComboBox1.Items.Clear()
For i=0 to 1
  ComboBox1.Items.Add(EthernetIPForCLXCom1.Read("Partnum[" & i & "].PartNumber"))
Next

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Populate combobox with PartNumbers from PLC
« Reply #2 on: July 12, 2016, 06:02:13 PM »
Thanks, Archie.

I was thinking of using GettagList and if TagName equal to PartNum then populate, but your solution should works!
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Populate combobox with PartNumbers from PLC
« Reply #3 on: July 14, 2016, 10:13:10 PM »
I learned something new, you can also populate a combobox without using the for loop, use DataSource instead.
Code: [Select]
        '* Retrieve available ports and add to combo box
        Dim ports() As String = System.IO.Ports.SerialPort.GetPortNames()
        Array.Sort(ports)
        cmbPortName.DataSource = ports
        cmbPortName.SelectedIndex = 0
« Last Edit: July 14, 2016, 10:31:09 PM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================