7 Replies - 845 Views - Last Post: 30 March 2013 - 09:09 AM Rate Topic: -----

#1 dery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 13

COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 02:42 AM

I have develop a visual basic program that allows students to choose from objective answers using radiobuttons. my problem is how do i write the code to calculate the number of correct answers a student gets after going through the program. the total number of questions is 40
Is This A Good Question/Topic? 0
  • +

Replies To: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,120
  • Joined: 12-December 12

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 02:51 AM

Post some relevant code wrapped in code-tags.

Is this for VB6 or VB.NET?
Was This Post Helpful? 0
  • +
  • -

#3 dery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 13

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 03:07 AM

it is VB 10

Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click

If RadioButton1.Checked = True Then
Label3.Text = "correct"
ElseIf RadioButton2.Checked = True Then
Label3.Text = "wrong"
ElseIf RadioButton3.Checked = True Then
Label3.Text = "wrong"
ElseIf RadioButton4.Checked = True Then
Label3.Text = "wrong"

End If

If RadioButton5.Checked = True Then
Label4.Text = "wrong"
ElseIf RadioButton6.Checked = True Then
Label4.Text = "correct"
ElseIf RadioButton7.Checked = True Then
Label4.Text = "wrong"
ElseIf RadioButton8.Checked = True Then
Label4.Text = "wrong"
End If

End Sub

Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged

End Sub
End Class
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 03:13 AM

Then this is VB.Net, so would be better suited in the correct forum.

As Andrew asked in his post, please edit your previous post and wrap it with the [ code] tags as explained in the background of the reply screen, that way it formats the code and makes it easier for people to read.
Was This Post Helpful? 0
  • +
  • -

#5 dery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 13

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 03:16 AM

Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click

If RadioButton1.Checked = True Then
Label3.Text = "correct"
ElseIf RadioButton2.Checked = True Then
Label3.Text = "wrong"
ElseIf RadioButton3.Checked = True Then
Label3.Text = "wrong"
ElseIf RadioButton4.Checked = True Then
Label3.Text = "wrong"

End If

If RadioButton5.Checked = True Then
Label4.Text = "wrong"
ElseIf RadioButton6.Checked = True Then
Label4.Text = "correct"
ElseIf RadioButton7.Checked = True Then
Label4.Text = "wrong"
ElseIf RadioButton8.Checked = True Then
Label4.Text = "wrong"
End If

End Sub

Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged

End Sub
End Class

Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
        
        [code]If RadioButton1.Checked = True Then
            Label3.Text = "correct"
        ElseIf RadioButton2.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton3.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton4.Checked = True Then
            Label3.Text = "wrong"
        End If

        If RadioButton5.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton6.Checked = True Then
            Label4.Text = "correct"
        ElseIf RadioButton7.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton8.Checked = True Then
            Label4.Text = "wrong"
        End If

    End Sub


Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged

End Sub
End Class
[/code]

Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
        
        If RadioButton1.Checked = True Then
            Label3.Text = "correct"
        ElseIf RadioButton2.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton3.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton4.Checked = True Then
            Label3.Text = "wrong"

        End If

        If RadioButton5.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton6.Checked = True Then
            Label4.Text = "correct"
        ElseIf RadioButton7.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton8.Checked = True Then
            Label4.Text = "wrong"
        End If

    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,120
  • Joined: 12-December 12

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 03:33 AM

Did you put the different sets of radiobuttons in groupboxes so that they are mutually exclusive (you can only choose one)? Then you could add the same event handler to the different groups to store which answer they chose:

Private m_Group1SelectedRadioButton As RadioButton

Private Sub RadioButtonGroup1_CheckedChanged( _
        ByVal sender As Object, ByVal e As EventArgs) Handles _
    RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, _
    RadioButton3.CheckedChanged

    Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
    If SourceControl.Checked Then
        m_Group1SelectedRadioButton = SourceControl
    End If
End Sub

I would also put all of these groupboxes in the same panel to make it easier to loop through them.

Anyway, you could loop through all the labels looking for the word "correct":

        Dim correctAns As Integer = 0
        For Each ctl In Me.Controls
            If TypeOf ctl Is Label Then
                If DirectCast(ctl, Label).Text = "correct" Then
                    correctAns += 1
                End If
            End If
        Next

This assumes, of course, that all the questions have already been marked as "correct" or "wrong".

BTW When you create your post there is a Preview button that you can use to check your post, before posting.

This post has been edited by andrewsw: 30 March 2013 - 03:37 AM

Was This Post Helpful? 0
  • +
  • -

#7 dery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 13

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 08:59 AM

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles     RadioButton1.CheckedChanged
        
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        
    End Sub

    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
        
        If RadioButton1.Checked = True Then
            Label3.Text = "correct"
        ElseIf RadioButton2.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton3.Checked = True Then
            Label3.Text = "wrong"
        ElseIf RadioButton4.Checked = True Then
            Label3.Text = "wrong"

        End If

        If RadioButton5.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton6.Checked = True Then
            Label4.Text = "correct"
        ElseIf RadioButton7.Checked = True Then
            Label4.Text = "wrong"
        ElseIf RadioButton8.Checked = True Then
            Label4.Text = "wrong"
        End If

    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        
    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click

    End Sub

    Private Group1SelectedRadioButton As RadioButton
    Private Sub Group1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Group1.Enter

    End Sub
    Private Sub RadioButtonGroup1_CheckedChanged( _
            ByVal sender As Object, ByVal e As EventArgs) Handles _
        RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, _
        RadioButton3.CheckedChanged

        Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
        If SourceControl.Checked Then
            Group1SelectedRadioButton = SourceControl

        End If
    End Sub



thank you for th corrections but i kindly look at the next codes i have sent. i tried it but i didnot see the number of corrects
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,120
  • Joined: 12-December 12

Re: COUNTING THE NUMBER OF CORRECTS A STUDENT HAD

Posted 30 March 2013 - 09:09 AM

Yeah, you won't do. As far as I can tell, all you've done is copy and paste the code sample that I provided. It won't miraculously pop-up with a total. You need to study the code, understand it, and adapt it to fit your application.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1