show the result of my quiz

hi everyone
i made a quiz app with these codes:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim map1 As Map
    Dim listview1 As ListView
    Dim rbanswer1 As RadioButton
    Dim rbanswer2 As RadioButton
    Dim rbAnswer3 As RadioButton
    Dim theQuestion As Int
    Dim QuestionNumber As Int
    Dim correctanswer As String
    Dim lblactualquestion As Label
    Dim lblquestionnumber As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("test1")
    QuestionNumber = 1
    RandomizeQuestions
    map1.Initialize
end sub
Sub RandomizeQuestions
   
    lblquestionnumber.text = QuestionNumber
   
    ''''''''''''''''''''
    'Initialize the Map'
    ''''''''''''''''''''
    map1.Initialize

    '''''''''''''''''''''''''''''''''''''''''''
    'Use the map to create true random numbers'
    '''''''''''''''''''''''''''''''''''''''''''
    Do While map1.Size < 15

    map1.Put(Rnd(1, 16), "")

    Loop
   
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    'Take the random numbers and assign them to a list'
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    For i = 0 To map1.Size - 1
        listview1.AddSingleLine(map1.GetKeyAt(i))
    Next
   
    ''''''''''''''''''''''''''''''
    'Grab the first random number'
    ''''''''''''''''''''''''''''''
    theQuestion = listview1.GetItem(0)
   
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Get the question that corresponds to the correct number'
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    GetQuestion
   
End Sub
Sub GetQuestion
   
    ''''''''''''''''''''''''''''''''''''''''''
    'Create questions randomly and on the fly'
    ''''''''''''''''''''''''''''''''''''''''''
   
    If theQuestion = 1 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If

    If theQuestion = 2 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
   
    If theQuestion = 3 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
   
    If theQuestion = 4 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
   
    If theQuestion = 5 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 6 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 7 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 8 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 9 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 10 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion =11 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 12 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 13 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 14 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
    If theQuestion = 15 Then
        lblactualquestion.text = ""
        rbanswer1.Text = ""
        rbanswer2.Text = ""
        rbAnswer3.Text = ""
        correctanswer = ""
    End If
   
End Sub
Sub Button1_Click
   
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Check the answer submitted to determine right/wrong'
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    If rbanswer1.Checked = True Then
        If rbanswer1.Text = correctanswer Then
            StartActivity("timer1")
        Else
            StartActivity("timer2")
        End If
    End If
   
    If rbanswer2.Checked = True Then
        If rbanswer2.Text = correctanswer Then
            StartActivity("timer1")
        Else
            StartActivity("timer2")
        End If
    End If
   
    If rbAnswer3.Checked = True Then
        If rbAnswer3.Text = correctanswer Then
            StartActivity("timer1")
        Else
            StartActivity("timer2")
        End If
    End If
   
    '''''''''''''''''''''''''''''''''''''''
    'Reset radio buttons for next question'
    '''''''''''''''''''''''''''''''''''''''
    rbanswer1.Checked = False
    rbanswer2.Checked = False
    rbAnswer3.Checked = False
   
    ''''''''''''''''''''''''''''
    'Update the question number'
    ''''''''''''''''''''''''''''
    QuestionNumber = QuestionNumber + 1
   
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Update the label so it says the correct question number'
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   
   
    If QuestionNumber = 2 Then
       
        theQuestion = listview1.GetItem(1)
        GetQuestion
       
    End If

   
    If QuestionNumber = 3 Then
       
        theQuestion = listview1.GetItem(2)
        GetQuestion
       
    End If
   
    If QuestionNumber = 4 Then
       
        theQuestion = listview1.GetItem(3)
        GetQuestion
       
    End If
   
    If QuestionNumber = 5 Then
       
        theQuestion = listview1.GetItem(4)
        GetQuestion
       
    End If
   
    If QuestionNumber = 6 Then
       
        theQuestion = listview1.GetItem(5)
        GetQuestion
       
    End If
    If QuestionNumber = 7 Then
       
        theQuestion = listview1.GetItem(6)
        GetQuestion
       
    End If
    If QuestionNumber = 8 Then
       
        theQuestion = listview1.GetItem(7)
        GetQuestion
       
    End If
    If QuestionNumber = 9 Then
       
        theQuestion = listview1.GetItem(8)
        GetQuestion
       
    End If
    If QuestionNumber = 10 Then
       
        theQuestion = listview1.GetItem(9)
        GetQuestion
       
    End If
    If QuestionNumber = 11 Then
       
        theQuestion = listview1.GetItem(10)
        GetQuestion
       
    End If
    If QuestionNumber = 12 Then
       
        theQuestion = listview1.GetItem(11)
        GetQuestion
       
    End If
    If QuestionNumber =13 Then
       
        theQuestion = listview1.GetItem(12)
        GetQuestion
       
    End If
    If QuestionNumber = 14 Then
       
        theQuestion = listview1.GetItem(13)
        GetQuestion
       
    End If
    If QuestionNumber = 15 Then
       
        theQuestion = listview1.GetItem(14)
        GetQuestion
       
    End If
   
    If QuestionNumber > 15 Then
       
        StartActivity("endoftest")
        Activity.Finish
    End If
   
End Sub

i want to show the result of quiz in activity "end of test" like this:
correct answer:7
wrong answer:8.
can anyone help me plz.:(
 
hi kpmaster.i dont have problem with transfering the result to end of test.i dont know how to make an int and add numbers of the correct answers
to it.i used this code but it did not work:
B4X:
Sub rbanswer1_CheckedChange(checked As Boolean)
If rbanswer1.checked=True Then
If rbanswer1.Text=correctanswer Then
test=1
Else
test=-1
End If
End If

End Sub
Sub rbanswer2_CheckedChange(checked As Boolean)
If rbanswer2.checked=True Then
If rbanswer2.Text=correctanswer Then
test=1
Else
test=-1
End If
End If
End Sub
Sub rbanswer3_CheckedChange(checked As Boolean)
If rbAnswer3.checked=True Then
If rbAnswer3.Text=correctanswer Then
test=1
Else
test=-1
End If
End If
End Sub
 
Upvote 0

KPmaster

Member
Licensed User
Longtime User
You need to save each answer to use them values at the end of the quiz.
Try defining an array of integer. Below is your code modified with it.

B4X:
Sub Globals
Dim test(3) as Int
End Sub

Sub rbanswer1_CheckedChange(checked As Boolean)
If rbanswer1.checked=True Then
If rbanswer1.Text=correctanswer Then
test(0)=1
Else
test(0)=-1
End If
End If

End Sub
Sub rbanswer2_CheckedChange(checked As Boolean)
If rbanswer2.checked=True Then
If rbanswer2.Text=correctanswer Then
test(1)=1
Else
test(1)=-1
End If
End If
End Sub
Sub rbanswer3_CheckedChange(checked As Boolean)
If rbAnswer3.checked=True Then
If rbAnswer3.Text=correctanswer Then
test(3)=1
Else
test(3)=-1
End If
End If
End Sub
 
Upvote 0
Top