Ciao a tutti, ho realizzato un semplice quiz in Vb.net che sfrutta un database xml.
sull'interfaccia grafica ho una textbox per l'inserimento della domanda
e tre radiobutton per le risposte.
Se osservate il codice che vi posto, noterete che i tre radiobutton si comportano esattamente nella stessa maniera, per questo chiedo:
anzichè scrivere codice ripetitivo per ogni radiobutton mi insegnate un modo per generalizzare il comportamento dei 3 in un' unica espressione? grazie!!
codice:
Public Class GraficaQuiz
Dim punti As Integer
Dim index As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (RadioButton1.Checked = True) And (Questions.Item(index + 15).RValore.ToString = "V") Then
punti = punti + 1
lblScore.Text = punti
End If
If (RadioButton1.Checked = True) And (Questions.Item(index + 15).RValore.ToString = "F") Then
Label1.Text = "Hai sbagliato!"
End If
If (RadioButton2.Checked = True) And (Questions.Item(index + 16).RValore.ToString = "V") Then
punti = punti + 1
lblScore.Text = punti
End If
If (RadioButton2.Checked = True) And (Questions.Item(index + 16).RValore.ToString = "F") Then
Label1.Text = "Hai sbagliato!"
End If
If (RadioButton3.Checked = True) And (Questions.Item(index + 17).RValore.ToString = "V") Then
punti = punti + 1
lblScore.Text = punti
End If
If (RadioButton3.Checked = True) And (Questions.Item(index + 17).RValore.ToString = "F") Then
Label1.Text = "Hai sbagliato!"
End If
End Sub