Author Topic: Control Logix array to Excel in 2024  (Read 1537 times)

Peter D

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Control Logix array to Excel in 2024
« Reply #15 on: November 11, 2024, 09:06:04 PM »
Thanks SO much to Archie and Bachpie for tutoring me a little.  I now have an AdvancedHMI with a single button.  All my Visual Basic code is in the button routine.  When you push the button it reads two arrays of 400 integers from the RsLogix PLC and writes them into an existing spreadsheet HistogramData.xlsx (overwriting the previous data).  I have a second spreadsheet that links to HistogramData and charts and analyses it.

My code looks like this:

Private Sub BasicButton1_Click(sender As Object, e As EventArgs) Handles BasicButton1.Click
    Dim Hist500Data() As String = EthernetIPforCLXCom1.Read("Histogram500[0]", 400)
    Dim Hist1000Data() As String = EthernetIPforCLXCom1.Read("Histogram1000[0]", 400)
    Dim StrNumber As String
    Dim filepath As String = ".\HistogramData.xlsx"

    Using WB As New ClosedXML.Excel.XLWorkbook(filepath)

        For i As Integer = 0 To Hist500Data.GetLength(0) - 1

            If IsNumeric(Hist500Data(i)) Then
                WB.Worksheet(1).Cell(i + 2, 2).Value = CInt(Hist500Data(i))
            Else WB.Worksheet(1).Cell(i + 2, 2).Value = 0
            End If
            If IsNumeric(Hist1000Data(i)) Then
                WB.Worksheet(1).Cell(i + 2, 3).Value = CInt(Hist1000Data(i))
            Else WB.Worksheet(1).Cell(i + 2, 3).Value = 0
            End If
        Next

        WB.Save()
    End Using
End Sub

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Control Logix array to Excel in 2024
« Reply #16 on: November 12, 2024, 10:45:11 AM »
First of all, I appreciate the effort, but I noticed that my name was spelled incorrectly. While it may have been a mistake the first time, it was intentional the second time. So, thank you for that effort.

Secondly, what I provided was more than just a "tutoring me a little." I essentially shared the entire code with you.
« Last Edit: November 12, 2024, 10:47:02 AM 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.
===================================================

Peter D

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Control Logix array to Excel in 2024
« Reply #17 on: November 12, 2024, 11:16:45 AM »
Bachphi, Nothing but gratitude from this corner and I'm so sorry I misspelled your name!  You're right.  The tutoring you and Archie did was of the "Here is exactly how to do it" sort and much appreciated.  I certainly didn't mean to offend anyone, my first time in the forum here.  The help you and Archie gave was right on target and very prompt.  That is something generously given and very much appreciated.

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Control Logix array to Excel in 2024
« Reply #18 on: November 12, 2024, 12:07:56 PM »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================