user2887738
user2887738

Reputation: 1

What does this mean: Value of type '1-dimensional array of String' cannot be converted to 'String'.?

I keep getting an error in my code:

Public Class frmPresentTest
    Dim correctAnswer As Double
    Dim i As Int32
    Dim wrongAnswer As Double
    Dim responses(((noOfQuestions - 1) + 1) - 1) As String

    Private Sub cmdFinished_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFinished.Click
        Dim str1 As String = "Correct Answer     Your Answer"
        FindChecked(i)
        Dim num2 As Double = 0
        Dim num3 As Integer = (noOfQuestions - 1)
        Dim num1 As Integer = 0
        Do While (num1 <= num3)
            If (responses(num1) <> "*") Then
                If (responses(num1) = test(num1).correctAnswer) Then
                    num2 = (num2 + correctAnswer)
                Else
                    num2 = (num2 - wrongAnswer)
                End If
            End If
            str1 = New String() {str1 & "  " & test(num1).correctAnswer & "    " & responses(num1), " "}
            num1 = (num1 + 1)

        Loop
        str1 = str1 & " * indicates that you did answer that question "
        str1 = str1 & "  Your score is: " & num2.ToString()
        MsgBox(str1, MsgBoxStyle.OkOnly, "Test Results")
        tookTest = True
        frmTestGen.Show()
        Me.Hide()

    End Sub

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        FindChecked(i)
        i = (i + 1)
        If (i = (noOfQuestions - 1)) Then
            cmdNext.Visible = False
            cmdFinished.Visible = True
        End If
        ShowQuestion(i)
    End Sub

    Public Sub FindChecked(ByRef i As Int32)
        If (OptA.Checked) Then
            responses(i) = "A"
        ElseIf (optB.Checked) Then
            responses(i) = "B"
        ElseIf (optC.Checked) Then
            responses(i) = "C"
        ElseIf (optD.Checked) Then
            responses(i) = "D"
        Else
            responses(i) = "*"
        End If
    End Sub

    Private Sub frmPresentTest_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        correctAnswer = (100 / noOfQuestions)
        wrongAnswer = (correctAnswer / 2)
        i = 0
        OptA.Checked = False
        cmdNext.Visible = True
        cmdFinished.Visible = False
        ShowQuestion(i)
    End Sub

    Public Sub ShowQuestion(ByVal i As Int32)
        lblCount.Text = (i + 1).ToString() & "."
        OptA.Checked = False
        optB.Checked = False
        optC.Checked = False
        optD.Checked = False
        lblQuestion.Text = test(i).question
        OptA.Text = test(i).choiceA
        optB.Text = test(i).choiceB
        optC.Text = test(i).choiceC
        optD.Text = test(i).choiceD
    End Sub

End Class

str1 = New String() {str1 & " " & test(num1).correctAnswer & " " & responses(num1), " "} is what I'm having problems with.

Upvotes: 0

Views: 1191

Answers (2)

Steve
Steve

Reputation: 5545

It means you should learn how to do one of the following:

  • Use google (you have a few "What does this mean" questions that can be answered by any search engine)
  • Ask your teacher
  • Look at all the code your fellow classmates have gotten from SO in the last 2 days while making thier own BlackJack game.

Upvotes: 0

OneFineDay
OneFineDay

Reputation: 9024

You originally declared str1 as a string and str1 = New String() = String Array not a string. Why not do this:

str1 = str1 & "  " & test(num1).correctAnswer & "    " & responses(num1)

Upvotes: 1

Related Questions