2013-10-17 31 views
0

我不断收到一个错误在我的代码:这是什么意思:类型'字符串的一维数组'的值不能被转换为'字符串'。

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 =新建字符串(){STR1 & “” &测试(NUM1).correctAnswer & “” &反应(NUM1)“,“}是我遇到的问题。

+0

该错误的哪部分你不明白? – OneFineDay

+0

为什么我得到“一维数组的字符串”不能转换为“字符串”。 – user2887738

+0

什么是你想让它看起来像当你显示它。您正在创建一个具有单个索引的新字符串数组,并试图将其分配给一个常规字符串。这就是你得到错误的原因。我相信DonA的回答是你需要的,除了我将它们与VbCrLf而不是空格分开。 –

回答

1

您最初将str1声明为字符串,str1 = New String() = String数组不是字符串。为什么不这样做:

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

我的错误消失了!谢谢! – user2887738

+1

标记为答案 - 谢谢。 – OneFineDay

0

这意味着你应该学习如何执行下列操作之一:

  • 使用谷歌(你可以通过回答几个“这是什么意思”的问题任何搜索引擎)
  • 问问你的老师
  • 看看你的同学们在过去的2天中从同胞那里得到的所有代码,同时做出他们自己的大酒杯游戏。
相关问题