Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Vb.NET - Eliminazione Domande già estratte - Quiz
Forum - C# / VB.NET - Vb.NET - Eliminazione Domande già estratte - Quiz

Avatar
Light (Normal User)
Newbie


Messaggi: 17
Iscritto: 25/05/2012

Segnala al moderatore
Postato alle 23:08
Giovedì, 03/07/2014
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
PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 23:54
Giovedì, 03/07/2014
Codice sorgente - presumibilmente VB.NET

  1. dim Lst_Domande as new List(of string)
  2.  
  3.    Public Sub EstrazioneDomande()
  4.         strSQL = "SELECT * FROM domande ORDER BY RAND() LIMIT 1;"
  5.         CONNECTION.Open()
  6.        do
  7.         cmd = New MySqlCommand(strSQL, CONNECTION)
  8.         dr = cmd.ExecuteReader()
  9.         Do While dr.Read()
  10.             domanda = (dr.Item("Domanda").ToString())
  11.             Risposta1 = (dr.Item("Risposta1").ToString())
  12.             Risposta2 = (dr.Item("Risposta2").ToString())
  13.             Risposta3 = (dr.Item("Risposta3").ToString())
  14.             RispostaEsatta = (dr.Item("RispostaEsatta").ToString())
  15.         Loop
  16.         'se la domanda è presente nella lista, looppa
  17.         Loop While Lst_Domande.contains(domanda)
  18.         Lst_Domande.add(domanda)
  19.         dr.Close()
  20.         cmd.Dispose()
  21.         CONNECTION.Close()
  22.     End Sub



If ok Then GOTO Avanza else GOTO Inizia

PM Quote
Avatar
Light (Normal User)
Newbie


Messaggi: 17
Iscritto: 25/05/2012

Segnala al moderatore
Postato alle 0:04
Venerdì, 04/07/2014
Ho provato, non cambia nulla

PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 1:02
Venerdì, 04/07/2014
non so, ma il concetto è semplice ripeti fin quando non trovi una nuova domanda


If ok Then GOTO Avanza else GOTO Inizia

PM Quote