codice:
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Dim valoreMemorizzato As New StringBuilder
Dim dictionary As New Dictionary(Of CheckBox, TextBox)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dictionary.Add(Me.CheckBox1, Me.TextBox1)
dictionary.Add(Me.CheckBox2, Me.TextBox1)
dictionary.Add(Me.CheckBox3, Me.TextBox2)
dictionary.Add(Me.CheckBox4, Me.TextBox2)
dictionary.Add(Me.CheckBox5, Me.TextBox3)
dictionary.Add(Me.CheckBox6, Me.TextBox3)
dictionary.Add(Me.CheckBox7, Me.TextBox4)
dictionary.Add(Me.CheckBox8, Me.TextBox4)
dictionary.Add(Me.CheckBox9, Me.TextBox5)
dictionary.Add(Me.CheckBox10, Me.TextBox5)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim currentCheckBox As Control
valoreMemorizzato.Remove(0, valoreMemorizzato.Length)
For Each currentCheckBox In Me.Controls
If currentCheckBox.GetType() Is GetType(CheckBox) Then
If CType(currentCheckBox, CheckBox).Checked Then
Dim valueToAdd As String
If valoreMemorizzato.Length > 0 Then
valueToAdd = "; " & dictionary(currentCheckBox).Text
Else
valueToAdd = dictionary(currentCheckBox).Text
End If
valoreMemorizzato.Append(valueToAdd)
End If
End If
Next
Label1.Text = valoreMemorizzato.ToString()
End Sub
End Class
Può andare?