我有一系列分数来自文本文件,我正在尝试循环遍历它们以添加所有分数。分数现在是String,所以我需要帮助将它们转换为整数并使用循环将它们全部添加。
需要转换和添加的分数是p1,p2,p3,p4,p5,p6,exam1,exam2
现在是我的代码。任何帮助,将不胜感激;谢谢!
Imports System.IO
Public Class Form1
Dim textFile As String
Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
OpenFileDialog1.ShowDialog()
textFile = OpenFileDialog1.FileName
Dim data() As String = File.ReadAllLines(textFile)
Dim myArray As String = data(0)
Dim studentInfo() = myArray.Split(","c)
Dim studentname As String = studentInfo(0)
Dim subject As String = studentInfo(1)
Dim semester As String = studentInfo(2)
Dim photo As String = studentInfo(3)
Dim p1 As String = studentInfo(4)
Dim p2 As String = studentInfo(5)
Dim p3 As String = studentInfo(6)
Dim p4 As String = studentInfo(7)
Dim p5 As String = studentInfo(8)
Dim p6 As String = studentInfo(9)
Dim exam1 As String = studentInfo(10)
Dim exam2 As String = studentInfo(11)
lblName.Text = studentname
lblSubject.Text = subject
lblSemester.Text = semester
PictureBox1.Image = Image.FromFile(photo)
lblP1.Text = p1
lblP2.Text = p2
lblP3.Text = p3
lblP4.Text = p4
lblP5.Text = p5
lblP6.Text = p6
lblExam1.Text = exam1
lblExam2.Text = exam2
End Sub
End Class
答案 0 :(得分:0)
我认为你误解了阵列是什么。
创建数组:
Dim p as integer(6)
将数据放入数组
p(1) = studentInfo(4)
p(2) = studentInfo(5)
'etc
从数组中获取数据
b = p(1)
循环播放数组:
For i as Integer = 1 to 6
total += p(i)
Next