
Originally Posted by
cicatrix
Maybe I didn't understand what exactly qsecofr wanted, but wouldn't a Dictionary collection fit the purpose of accessing a certain value by its name (or key)?
Sure would
Code:
Dim totals As New Dictionary(Of String, Integer)
Private Sub someButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click
Dim b As Button = CType(sender, Button)
Dim key As String = CStr(b.Tag)
totals(key) += 1
'proof
Debug.WriteLine("A " & totals("ATotal"))
Debug.WriteLine("B " & totals("BTotal"))
End Sub
Private Sub Form1_Shown(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Shown
Button1.Tag = "ATotal"
Button2.Tag = "BTotal"
totals.Add(CStr(Button1.Tag), 0)
totals.Add(CStr(Button2.Tag), 0)
End Sub