我正在编写一个程序来读取包含一行的输入文件:
Scott Atchison,200,74
该文件包含大约 30 行不同的数据。我知道如何读入文件。读入文件后,将其拆分,然后需要进行计算(我知道该怎么做)。但是,我遇到的问题是输出文件,我只能将输入文件的最后一行获取到输出文件。这就是我现在所拥有的:
Public Class BMI
Dim data As String
Dim strName As String
Dim intWeight As Integer
Dim intHeight As Integer
Dim decBMI As Decimal
Private Sub btnInputFile_Click(sender As System.Object, e As System.EventArgs) Handles btnOpenFile.Click
    'User chooses a file
    OpenFile.ShowDialog()
    'Choose a file name into a label
    lblFileInput.Text = OpenFile.FileName
    Dim inputFile As New IO.StreamReader(lblFileInput.Text)
    Do While (inputFile.Peek() > -1)
        data = inputFile.ReadLine
        Dim fields() As String = data.Split(",")
        strName = fields(0)
        intWeight = fields(1)
        intHeight = fields(2)
        txtData.Text = txtData.Text & data & vbNewLine
    Loop
    FileClose()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveFile.Click
    SaveFile.ShowDialog()
    lblFileOutput.Text = SaveFile.FileName
    Dim output As IO.StreamWriter
    output = New IO.StreamWriter(lblFileOutput.Text)
    output.WriteLine(data)
End Sub
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    decBMI = (intWeight * 703 / (intHeight ^ 2))
    data = strName & ", " & decBMI
End Sub
结束类
在读取所有 30 行之前它不会写一行,还是我错过了一些东西,比如 while 循环?任何帮助,将不胜感激。