Author Topic: Selection scroll down list compactlogix  (Read 2010 times)

Nimesh

  • Newbie
  • *
  • Posts: 25
    • View Profile
Selection scroll down list compactlogix
« on: March 15, 2018, 11:30:06 PM »
Hi
I have compactlogix(with Eip module) having array of 20 string type members Containing job names to be sent to
Other Eip device. I want to creat scroll down list on AHMI  displaying  All members of string array and user can select one of them and Send it to current job tag (string) in plc.

How can I create such selection list in AHMI.

Thanks in advance.


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Selection scroll down list compactlogix
« Reply #1 on: March 16, 2018, 12:22:57 PM »
- From the Toolbox, add a ComboBox to your form
- In the Properties Window, select the lightening bolt icon to see a list of your event
- Find the event DropDown and click in its value field
- You will now be back to the event handler code
- Enter code similar to this:
Code: [Select]
    Private Sub ComboBox1_DropDown(sender As Object, e As EventArgs) Handles ComboBox1.DropDown
        ComboBox1.Items.Clear()

        Dim MyStrings() As String = EthernetIpForCLXCom1.Read("StringTag", 20)

        For index = 0 To MyStrings.Length - 1
            ComboBox1.Items.Add(MyStrings(index))
        Next
    End Sub

Nimesh

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Selection scroll down list compactlogix
« Reply #2 on: March 16, 2018, 02:35:38 PM »
Thanks Archie,
now i can see the tags from array and select one. now i want to send selected tag to string type tag in PLC , "Current_Job" using a confirm selection button .
 how can i write selected value to Current_Job in PLC using Confirmation button.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Selection scroll down list compactlogix
« Reply #3 on: March 16, 2018, 02:42:49 PM »
Add this code after the End Sub of the code above:
Code: [Select]
    Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
        EthernetIpForCLXCom1.Write("Current_Job", ComboBox1.Text)
    End Sub
« Last Edit: March 16, 2018, 03:19:34 PM by Archie »

Nimesh

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Selection scroll down list compactlogix
« Reply #4 on: March 16, 2018, 03:09:52 PM »

i am getting this error after entering code for Current_Job

Error   BC30057   Too many arguments to 'Friend WithEvents EthernetIPforCLXCom1 As EthernetIPforCLXCom'.   AdvancedHMI


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Selection scroll down list compactlogix
« Reply #5 on: March 16, 2018, 03:19:57 PM »
I forgot the Write . The code above has been corrected.

Nimesh

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Selection scroll down list compactlogix
« Reply #6 on: March 17, 2018, 03:58:15 AM »
Thanks Archie,
Its working . I want to add/edit and delete the strings in array
To add new string I want to go to next empty place in the array. How can we  add /delete and edit array members?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Selection scroll down list compactlogix
« Reply #7 on: March 18, 2018, 03:28:34 PM »
You could possibly use the DataGridView control.

The attached picture 1 shows what it could look like when used in addition to the ComboBox and the whole code behind it is this:

Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
        ComboBox1.Items.Clear()

        Dim MyStrings() As String = EthernetIPforCLXCom1.Read("Controller_Tag_String", 20)

        For index = 0 To MyStrings.Length - 1
            ComboBox1.Items.Add(MyStrings(index))
        Next

        Me.dgvTags.RowCount = 21
        Me.dgvTags.ColumnCount = 2
        Me.dgvTags.AllowUserToOrderColumns = False
        Me.dgvTags.AllowUserToAddRows = False
        Me.dgvTags.AllowUserToDeleteRows = False

        Me.dgvTags.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.dgvTags.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        Me.dgvTags.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
        Me.dgvTags.Columns(0).HeaderCell.Value = "String Array"
        Me.dgvTags.Columns(0).ReadOnly = True

        Me.dgvTags.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.dgvTags.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        Me.dgvTags.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
        Me.dgvTags.Columns(1).HeaderCell.Value = "Value"

        For i As Integer = 0 To 19
            Me.dgvTags.Rows(i).Cells(0).Value = "Controller_Tag_String[" & i.ToString & "]"
            Me.dgvTags.Rows(i).Cells(1).Value = MyStrings(i).ToString
        Next

        Dim btnColumn As DataGridViewButtonColumn = New DataGridViewButtonColumn
        btnColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        btnColumn.HeaderText = "Apply"
        btnColumn.Text = "Apply"
        btnColumn.SortMode = DataGridViewColumnSortMode.NotSortable
        btnColumn.UseColumnTextForButtonValue = True
        btnColumn.DefaultCellStyle.Font = New Font("Arial", 8, FontStyle.Regular)
        Me.dgvTags.Columns.Add(btnColumn)
    End Sub

    Private Sub dgvTags_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTags.CellClick
        If e.ColumnIndex = 2 Then
            Dim valueToWrite As String
            If e.RowIndex >= 0 Then
                If Me.dgvTags.Rows(e.RowIndex).Cells(1).Value Is Nothing Then 'Delete current string
                    valueToWrite = ""
                Else
                    valueToWrite = Me.dgvTags.Rows(e.RowIndex).Cells(1).Value 'Replace current string
                End If

                Me.EthernetIPforCLXCom1.Write(Me.dgvTags.Rows(e.RowIndex).Cells(0).Value, valueToWrite)
                Me.ComboBox1.Items.Item(e.RowIndex) = valueToWrite
            End If
        End If
    End Sub

    Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
        EthernetIpForCLXCom1.Write("Current_Job", ComboBox1.Text)
    End Sub

The attached picture 2 shows what it could look like when used instead of the ComboBox and the whole code behind it is this:

Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim MyStrings() As String = EthernetIPforCLXCom1.Read("Controller_Tag_String", 20)

        Me.dgvTags.RowCount = 21
        Me.dgvTags.ColumnCount = 3
        Me.dgvTags.AllowUserToOrderColumns = False
        Me.dgvTags.AllowUserToAddRows = False
        Me.dgvTags.AllowUserToDeleteRows = False

        Me.dgvTags.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.dgvTags.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        Me.dgvTags.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
        Me.dgvTags.Columns(0).HeaderCell.Value = "String Array"
        Me.dgvTags.Columns(0).ReadOnly = True

        Me.dgvTags.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.dgvTags.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        Me.dgvTags.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
        Me.dgvTags.Columns(1).HeaderCell.Value = "Value"

        Me.dgvTags.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.dgvTags.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        Me.dgvTags.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
        Me.dgvTags.Columns(2).HeaderCell.Value = "Write To Tag"

        For i As Integer = 0 To 19
            Me.dgvTags.Rows(i).Cells(0).Value = "Controller_Tag_String[" & i.ToString & "]"
            Me.dgvTags.Rows(i).Cells(1).Value = MyStrings(i).ToString
        Next

        Dim btnColumn As DataGridViewButtonColumn = New DataGridViewButtonColumn
        btnColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        btnColumn.HeaderText = "Apply"
        btnColumn.Text = "Apply"
        btnColumn.SortMode = DataGridViewColumnSortMode.NotSortable
        btnColumn.UseColumnTextForButtonValue = True
        btnColumn.DefaultCellStyle.Font = New Font("Arial", 8, FontStyle.Regular)
        Me.dgvTags.Columns.Add(btnColumn)
    End Sub

    Private Sub dgvTags_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTags.CellClick
        If e.ColumnIndex = 3 Then
            Dim valueToWrite As String
            If e.RowIndex >= 0 Then
                If Me.dgvTags.Rows(e.RowIndex).Cells(1).Value Is Nothing Then 'Delete current string
                    valueToWrite = ""
                Else
                    valueToWrite = Me.dgvTags.Rows(e.RowIndex).Cells(1).Value 'Replace current string
                End If

                Me.EthernetIPforCLXCom1.Write(Me.dgvTags.Rows(e.RowIndex).Cells(0).Value, valueToWrite)

                If Not (String.IsNullOrWhiteSpace(Me.dgvTags.Rows(e.RowIndex).Cells(2).Value)) Then
                    Me.EthernetIPforCLXCom1.Write(Me.dgvTags.Rows(e.RowIndex).Cells(2).Value, valueToWrite)
                End If
            End If
        End If
    End Sub

You would need to replace all of the "Controller_Tag_String" text with the name of your string array.
You might also need to replace all of the "dgvTags" text with the name of your DataGridView control (whatever name you might give it once you add it to the form, the easiest option being to name it dgvTags).

If you research the DataGridView control then you could customize its features further.
« Last Edit: March 19, 2018, 12:34:50 PM by Godra »