AdvancedHMI Software
General Category => Open Discussion => Topic started by: Holmux on September 10, 2019, 07:58:16 AM
-
Hi All
I am trying to make a dynamic array using AdvancedHMIControls.basicButton and I am strucling a bit with getting a value from each button to the plc.
Dim xPos As Integer = 0
Dim yPos As Integer = 0
Dim n As Integer = 0
Dim p As Integer = -1
Dim s As String = ""
For i As Integer = 0 To 10
' Initialize one variable
btnArray(i) = New AdvancedHMIControls.BasicButton
Next i
While (n < 10)
With (btnArray(n))
s = (n + 1).ToString
.OutputType = 5
.PLCAddressClick = BValue
.ValueToWrite = n + 1
' .BackColor = Color.DarkGray
' .ForeColor = Color.Lime
.Width = 100 ' Width of button
.Height = 100 ' Height of button
p += 1
If (p = 5) Then ' Location of second line of buttons:
xPos = 0
yPos += 100
p = 0
End If
' Location of button:
.Left = xPos
.Top = yPos
' Add buttons to a Panel:
pnlButtons.Controls.Add(btnArray(n)) ' Let panel hold the Buttons
xPos = xPos + .Width ' Left of next button
n += 1
End With
End While
End Sub
Any help would be great.
Thanks
-
What addresses do you want the buttons to write to?
-
Hi Archie
I was using the tag "BValue"
/Holm
-
You need to put BValue in parenthesis since it is a tag name. This will make every button control the same bit
-
You could also simplify your code to look similar to this:
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xPos, yPos As Integer
Dim p As Integer = -1
For i As Integer = 1 To 10
' Let panel hold the Buttons - Toggle example
pnlButtons.Controls.Add(New AdvancedHMIControls.BasicButton With {
.ComComponent = Me.ModbusTCPCom1,
.PLCAddressClick = "0000" & i,
.Text = i,
.UseVisualStyleBackColor = True,
.OutputType = 4,
.Width = 100,
.Height = 100,
.Left = xPos,
.Top = yPos})
xPos += 100
p += 1
If (p = 4) Then ' Location of second line of buttons:
xPos = 0
yPos += 100
p = -1
End If
Next
End Sub
The attached 1st picture shows what it looks like with a MODRSsim2 simulator next to it (for this example).
Unless you really need array and "s" variable, just make changes as you need it to be.
The attached 2nd picture shows what it looks like with Highlight enabled (and also with a MODRSsim2 simulator next to it), the code is slightly changed:
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xPos, yPos As Integer
Dim p As Integer = -1
For i As Integer = 1 To 10
' Let panel hold the Buttons - Toggle example with Highlight
pnlButtons.Controls.Add(New AdvancedHMIControls.BasicButton With {
.ComComponent = Me.ModbusTCPCom1,
.PLCAddressClick = "0000" & i,
.PLCAddressHighlightX = "0000" & i,
.Text = i,
.OutputType = 4,
.Width = 100,
.Height = 100,
.Left = xPos,
.Top = yPos})
xPos += 100
p += 1
If (p = 4) Then ' Location of second line of buttons:
xPos = 0
yPos += 100
p = -1
End If
Next
End Sub
-
Thanks
This is great stuff :)