Salve, con il vostro aiuto ho sistemato il quiz, adesso vorrei eliminare le domande già estratte, ovvero se viene estratta una domanda, dopo aver risposto ad essa deve essere cancellata in modo da non ripetersi tale domanda, come posso fare?
Ecco il codice per l'estrazione della domanda random:
Public Sub EstrazioneDomande()
strSQL = "SELECT * FROM domande ORDER BY RAND() LIMIT 1;"
CONNECTION.Open()
cmd = New MySqlCommand(strSQL, CONNECTION)
dr = cmd.ExecuteReader()
Do While dr.Read()
domanda = (dr.Item("Domanda").ToString())
Risposta1 = (dr.Item("Risposta1").ToString())
Risposta2 = (dr.Item("Risposta2").ToString())
Risposta3 = (dr.Item("Risposta3").ToString())
RispostaEsatta = (dr.Item("RispostaEsatta").ToString())
Loop
dr.Close()
cmd.Dispose()
CONNECTION.Close()
End Sub
Il codice per l'estrazione dei dati in base alla domanda estratta prima:
Public Sub EstrazioneDati()
strSQL = "SELECT * FROM domande where Domanda = '" & domanda & "';"
CONNECTION.Open()
cmd = New MySqlCommand(strSQL, CONNECTION)
dr = cmd.ExecuteReader()
Do While dr.Read()
DomandaEstratta = (dr.Item("Domanda").ToString())
Dim Risposte As New List(Of String)
Risposte.Add(dr.Item("Risposta1").ToString())
Risposte.Add(dr.Item("Risposta2").ToString())
Risposte.Add(dr.Item("Risposta3").ToString())
RispostaEsattaEstratta = (dr.Item("RispostaEsatta").ToString())
Risposte.Add(RispostaEsattaEstratta)
Label1.Text = DomandaEstratta & "?"
Dim R As New Random
For i As Integer = 0 To Risposte.Count - 1
Dim Scambio As String = Risposte(i)
Dim j As Integer = R.Next(Risposte.Count)
Risposte(i) = Risposte(j)
Risposte(j) = Scambio
Next
RadioButton1.Text = Risposte(0)
RadioButton2.Text = Risposte(1)
RadioButton3.Text = Risposte(2)
RadioButton4.Text = Risposte(3)
Loop
dr.Close()
cmd.Dispose()
CONNECTION.Close()
End Sub
Il codice per il controllo delle risposte con assegnazione punti:
Public Sub ControlloRisposte()
If Risposta = RispostaEsattaEstratta Then
punti = punti + 1
EstrazioneDomande()
EstrazioneDati()
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
MsgBox(punti)
Else
EstrazioneDomande()
EstrazioneDati()
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
End If
End Sub
Ovviamente le domande non devono essere cancellate dal database, altrimenti non saranno disponibili ad altri partecipanti
Come posso fare? Grazie in anticipo
Ultima modifica effettuata da Light il 03/07/2014 alle 23:52 |