2013-08-02 122 views
0

每当我尝试运行我的节目,我不断收到,“从字符串转换‘59 60 65 75个国家转换字符串错误

错误’键入‘双师型’是无效的。”

我从一个名为scores.txt的文件中获取我的数据,该文件包含整数59,60,65,75。我不太清楚如何解决这个问题,VB已经提出了一些诸如确保该值小于无穷大(显然是),并确保源类型转换为目标类型。(这个我是如何调试不确定)有什么建议?这是我的代码

Public Class Form1 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnanalyze.Click 


     Dim scores() As String = 
      IO.File.ReadAllLines("scores.txt") 
     Dim intdata(scores.length - 1) As Double 'declare an array of type double to store the data of text file 

     Dim mean As Double 
     Dim sdeviation As Double = 0 
     For i As Integer = 0 To scores.length - 1 
      intdata(i) = CDbl(scores(i)) 

     Next 
     mean = intdata.Average 'mean is the average of the numbers in the collection 
     For j As Integer = 0 To intdata.Length - 1 
      sdeviation = +Math.Pow(intdata(j) - mean, 2) 

     Next 
     sdeviation = sdeviation/(intdata.Length) 
     sdeviation = Math.Sqrt(sdeviation) 
     lblmean.text = FormatNumber(mean) 
     lblsd.text = FormatNumber(sdeviation) 
     lblnumofexams.text = scores.length 
     Dim query = From score In scores 
        Let Sscore = score 
        Let grade = getGrade(score, mean, sdeviation) 
        Select Sscore, grade 
     dvgoutput.datasource = query.tolist 
     dvgoutput.currentcell = Nothing 
     dvgoutput.columns("Sscore").headertext = "score" 
     dvgoutput.columns("grade").headertext = "grade" 




    End Sub 
    Public Function getGrade(ByVal ES, ByVal m, ByVal s) As String 
     If ES >= m + (1.5 * s) Then 
      Return "A" 
     End If 
     If m + (0.5 * s) < +ES And ES < m + (1.5 * s) Then 
      Return "B" 
     End If 

     If m - (0.5 * s) <= ES And ES < m + (0.5 * s) Then 
      Return "C" 
     End If 

     If m - (1.5 * s) <= ES And ES < +m - (0.5 * s) Then 
      Return "D" 
     End If 

     If ES < m - (1.5 * s) Then 
      Return "F" 
     End If 
     Return "" 
    End Function 

End Class 
+0

我在这条线上得到一个错误“intdata(i)= CDbl(scores(i))” – user2596437

+0

这听起来像是在读所有的数字,而不仅仅是一个。因此无法将其转换。弄清楚如何一次输入一个数字。 – Jiminion

+0

如果您在文本文件的每一行都有一个分数,该怎么办? – Jiminion

回答

0

您需要在文本文件中每行有一个分数。

+0

那就对了!有效!谢谢! – user2596437

+0

太棒了!你能接受答案并且赞成吗? – Jiminion