0

In VB.net, I handle many button clicks in one method. Then I use a select case to figure out what to do with the request, see below:

Private Sub picT1_Click(sender As Object, e As EventArgs) Handles picT2.Click, picT3.Click, picT4.Click,

        Select Case sender.name
            Case "picT2"
                If PLC.T2Shutter = BitOff Then do something...
            Case "picT3"
                If PLC.T3Shutter = BitOff Then do something...
            Case "picT4"
                If PLC.T4Shutter = BitOff Then do something...
        End Select

End Sub

Since I am going to manipulate a variable with similar indexing (PLC.T2Shutter from picT2.Click event), how can I address the right variable by somehow using the received "2" in the name of the sender?

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Trey
  • 9
  • 3
  • see my answer below. If you didn't vote please do do and accept if that was the answer or ask for clarification – Jay Aug 03 '18 at 17:46
  • 1
    Perhaps it would be better to have `PLC.Shutter(shutterNumber)` instead of individually named properties for each one. Or `PLC.T.Shutter()`, etc. – Andrew Morton Aug 03 '18 at 19:57

0 Answers0