VB语法和表达式错误

时间:2014-01-06 23:27:42

标签: vb.net syntax-error

嘿我已经为多项选择测验完成了这段代码,但是继续两个语法错误和一个预期的表达式但不知道如何解决它。

Public Class Form1
    Dim questions(2, 4) As String    
    Dim answers(2) As String    
    Dim quesNum As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Operational Strategies Test"
        GetQuestions()
        quesNum = 1    
        Label1.Text = "Question " & quesNum & " of " & answers.Length    
        Label2.Text = questions(0, 0)

        RadioButton1.Text = questions(0, 1)    
        RadioButton2.Text = questions(0, 2)    
        RadioButton3.Text = questions(0, 3)    
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        If quesNum > 1 Then    
            quesNum -= 1    
            Label1.Text = "Question " & quesNum & " of 3"    
            Label2.Text = questions(quesNum - 1, 0)    
            RadioButton1.Text = questions(quesNum - 1, 1)    
            RadioButton2.Text = questions(quesNum - 1, 2)    
            RadioButton3.Text = questions(quesNum - 1, 3)   

            If btnNext.Text = "Submit" Then    
                btnNext.Text = "Next"    
            End If    
        End If   
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If RadioButton1.Checked = True Then    
            answers(quesNum - 1) = RadioButton1.Text    
        ElseIf RadioButton2.Checked = True Then    
            answers(quesNum - 1) = RadioButton2.Text    
        ElseIf RadioButton3.Checked = True Then    
            answers(quesNum - 1) = RadioButton3.Text    
        End If

        RadioButton1.Focus()

        If quesNum < 3 Then    
            quesNum += 1    
            Label1.Text = "Question " & quesNum & " of " & answers.Length    
            Label2.Text = questions(quesNum - 1, 0)    
            RadioButton1.Text = questions(quesNum - 1, 1)    
            RadioButton2.Text = questions(quesNum - 1, 2)    
            RadioButton3.Text = questions(quesNum - 1, 3)

            If quesNum = 3 Then    
                btnNext.Text = "Submit"    
            End If    
        Else    
            MarkTest()    
        End If
    End Sub

    Private Sub GetQuestions()    
        questions = New String(,) {{"How many colors are in a rainbow?", "5", "6", "7", "7"}, _    
        {"Who starred in Pirates of the Caribbean?", "Johnny Depp", "John Malkovich", "John Cusack", "Johnny Depp"}, _    
        {"What is the capital of Florida?", "Miami", "Tallahassee", "Jacksonville", "Tallahassee"}}    
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

试试这个

questions = {{"How many colors are in a rainbow?", "5", "6", "7", "7"}, _
{"Who starred in Pirates of the Caribbean?", "Johnny Depp", "John Malkovich", "John Cusack", "Johnny Depp"},
{"What is the capital of Florida?", "Miami", "Tallahassee", "Jacksonville", "Tallahassee"}}

并在此处阅读

How to: Initialize a Multidimensional Array