高级VB班的大学生转向论坛寻求帮助 - 我找到了一些代码示例,但是很难找出这个代码..任何和所有的帮助表示赞赏:)VB.net中.txt文件数组的求和元素
此应用程序导入一个.txt文件存储在bin中,调试文件夹名为data.txt ..20记录,每条记录3行,最后一行是学生的成绩,我需要通过将每个记录等级相加并除以20来平均等级,然后在显示平均值的第一个盒子上显示。
到目前为止,我已经得到了..
Dim objReader As IO.StreamReader
Dim intFill As Integer
Dim intCount As Integer = 0
Dim intAverage As Integer
Dim strLocationAndNameOfFile As String = "data.text"
If IO.File.Exists(strLocationAndNameOfFile) = True Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
Else
MsgBox("The file is not available. Restart the program when the file is avilable", , "Error")
Me.Close()
End If
If IO.File.Exists(strLocationAndNameOfFile) Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
Do While objReader.Peek <> -1
_strName(intCount) = Convert.ToString(objReader.ReadLine())
_strItemID(intCount) = Convert.ToString(objReader.ReadLine())
_intGrade(intCount) = Convert.ToInt32(objReader.ReadLine())
intCount += 1
Loop
objReader.Close()
End If
For intFill = 0 To (_strName.Length - 1)
*'intAverage = SUM OF ALL AVERAGES/LENGTH OF ARRAY -1*
Me.lstAverage.Items.Add(intAverage.ToString())
我米不知道我可以看到'Dim strLocationAndNameOfFile As String =“data.text”'working .. – christopher 2013-03-08 21:31:12
它看起来像你的大学教你使用类型前缀。你应该和那些教授聊聊......这曾经很重要,但不再推荐**。请参阅Microsoft自己的编码风格指南,尤其是[本节](http://msdn.microsoft.com/zh-cn/library/ms229045.aspx)(建议不要使用粗体字)“不要使用匈牙利语符号” 。 – 2013-03-08 21:50:44
此外,避免'File.Exists()'http://stackoverflow.com/q/673654/3043,因为这是一个高级的类,你应该知道关闭你的'objReader'对象在Finally块(可能通过一个使用块)。 – 2013-03-08 21:58:01