hello Masters,

How are you all doing? I just have a question. 

I am building this simple quiz application using asp.net/vb.net and sql server for the database. Now what I want to happen is that when I click on submit button, it will count all the correct answers of the user based on the radio button he clicks. 

I have two radio buttons and the correct answer for those two radio buttons is A, now if they click both A for those 2 radio buttons, they will get a score of two else if wrong, it won't count the incorrect answer.

Here is what I got: (I am very sorry for the messy code, I am new to loops)

Dim score As Integer = 0

    If RbAnswers1.SelectedValue = "A" Then

        For score = 0 To lbCorrectAnswerCount.Text.Count - 1

            score += 1

        Next score
        If RbAnswers2.SelectedValue = "A" Then
        Else
            lbCorrectAnswerCount.Text = score
            Exit Sub
        End If
    Else
        Exit Sub
        lbCorrectAnswerCount.Text = score

    End If

    lbCorrectAnswerCount.Text = score

Thank you in advance for your help.

Why do you need for loop? Is 'lbCorrectAnswerCount' a label?

Why can't you use your code as below?

Dim score As Integer = 0

 If RbAnswers1.SelectedValue = "A" Then

     score = score + 1

 End If

 If RbAnswers2.SelectedValue = "A" Then

    score = score + 1
 End If

lbCorrectAnswerCount.Text = score
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.