1
Support Questions / Re: Single dynamic Form for multiple (mostly) identical machines
« on: August 02, 2024, 08:56:23 PM »
Can't even attempt to argue with that. I'll need to go back and try some refactoring, cause I ended up repeating myself quite a bit. I may or may not be setting shown_value to called_value three times in a row...
Edit:
Here's a skeleton version of what I came up with, but also with slightly better thought out code. Turns out I was right - the path I had put the solution in on my personal laptop was too long to add the seven segment display haha.
In MainForm.vb
And in Page2.vb
This seems to work quite well for what I intended.
Another edit: I've come to realize I can remove every "Me.whatever" in there - don't need Me.called_value for this, for example.
Edit:
Here's a skeleton version of what I came up with, but also with slightly better thought out code. Turns out I was right - the path I had put the solution in on my personal laptop was too long to add the seven segment display haha.
In MainForm.vb
Code: [Select]
Private Sub Line1_Click(sender As Object, e As EventArgs) Handles line1.Click
Page2.called_value = 1
Page2.Update_Form()
End Sub
Private Sub Line2_Click(sender As Object, e As EventArgs) Handles line2.Click
Page2.called_value = 2
Page2.Update_Form()
End Sub
...
And in Page2.vb
Code: [Select]
Public called_value As Integer
Private shown_value As Integer
Private pe_list As New List(Of PilotLight)
Private address_ends As New List(Of String) From {
"[4].6",
"[4].7",
"[5].0"
}
Private Sub Collection_Maker()
pe_list.Add(Me.pe1)
pe_list.Add(Me.pe2)
pe_list.Add(Me.pe3)
End Sub
Public Sub Update_Form()
If Me.IsHandleCreated Then
Else
Me.Show()
End If
shown_value = called_value
Select Case shown_value
Case 1
rad1.Checked = True
PLC_Comm.ProcessorSlot = 1
Case 2
rad2.Checked = True
PLC_Comm.ProcessorSlot = 1
Case 3
rad3.Checked = True
PLC_Comm.ProcessorSlot = 2
Case 4
rad4.Checked = True
PLC_Comm.ProcessorSlot = 2
End Select
SevenSeg.Value = shown_value
Update_PEs()
End Sub
Private Sub Update_PEs()
Dim index = 0
For Each pe In pe_list
pe.PLCAddressValue = "DCP_IO_" & shown_value & ".I.Data" & address_ends.Item(index)
index += 1
Next
End Sub
Private Sub Debug_Logger()
Debug.WriteLine("PLC Slot: " & PLC_Comm.ProcessorSlot)
Debug.WriteLine("PE 1 Address: " & Me.pe1.PLCAddressValue)
Debug.WriteLine("PE 2 Address: " & Me.pe2.PLCAddressValue)
Debug.WriteLine("PE 3 Address: " & Me.pe3.PLCAddressValue)
End Sub
Private Sub Page2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Collection_Maker()
End Sub
Private Sub Rad1_Clicked(sender As Object, e As EventArgs) Handles rad1.Click
Me.called_value = 1
Update_Form()
End Sub
Private Sub Rad2_Clicked(sender As Object, e As EventArgs) Handles rad2.Click
Me.called_value = 2
Update_Form()
End Sub
...
Private Sub BasicButton1_Click(sender As Object, e As EventArgs) Handles BasicButton1.Click
Debug_Logger()
End Sub
End Class
This seems to work quite well for what I intended.
Another edit: I've come to realize I can remove every "Me.whatever" in there - don't need Me.called_value for this, for example.