我正在尝试创建一个解决方案,该解决方案将从文本文件中提取员工信息,将其加载到数组,然后在按钮为时从数组中填充了一系列文本框单击。
我已经取得了一些进步,到了我从数组中获取数据并将其放入文本框中的位置。但是,只有单个字母填充文本框,而不是完整数据。
我已经附上了我一直在努力实现目标的代码,但是我确实在接下来要去的地方打了一个障碍。
用于参考文本文件中的数据是:
Janice
琼斯
101
5.25
克里斯
O Connel
102
5.35
卡伦
Fisk
103
6.00
汤姆
Winn
104
5.75
Private Sub nextButton_Click(sender As Object, e As EventArgs) Handles nextButton.Click
Dim EmpoyeeStreamReader As New StreamReader("employee.txt")
Dim EmployeeLineInfoString As String
Dim EmployeeIndex As Decimal
EmployeeLineInfoString = EmpoyeeStreamReader.ReadLine()
Dim EmployeeArray = (EmployeeLineInfoString).ToString
EmployeeIndex = 0
Try
For EmployeeIndex = 0 To 16
firstNameTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
lastNameTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
employeeNumberTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
payRateTextBox.Text = EmployeeArray(EmployeeIndex)
Next
For EmployeeIndex = 5 To 16
firstNameTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
lastNameTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
employeeNumberTextBox.Text = EmployeeArray(EmployeeIndex)
EmployeeIndex += 1
payRateTextBox.Text = EmployeeArray(EmployeeIndex)
Next
Catch ex As Exception
MessageBox.Show("All Employee's have been entered")
End Try
尝试这样的东西(尽管最好以表单级别声明您的流程图!(:
Private Sub nextButton_Click(sender As Object, e As EventArgs) Handles nextButton.Click
Static EmpoyeeStreamReader As StreamReader = Nothing
If IsNothing(EmpoyeeStreamReader) Then
EmpoyeeStreamReader = New StreamReader("employee.txt")
End If
If Not EmpoyeeStreamReader.EndOfStream Then
Try
firstNameTextBox.Text = EmpoyeeStreamReader.ReadLine
lastNameTextBox.Text = EmpoyeeStreamReader.ReadLine
employeeNumberTextBox.Text = EmpoyeeStreamReader.ReadLine
payRateTextBox.Text = EmpoyeeStreamReader.ReadLine
Catch ex As Exception
MessageBox.Show("Error Reading Record: Insufficient Number of Lines!")
End Try
Else
MessageBox.Show("No more records!")
EmpoyeeStreamReader.Close()
EmpoyeeStreamReader = Nothing
End If
End Sub