阅读文件的问题

时间:2017-04-15 17:05:36

标签: vb.net

目前在从文件中读取数据并将其分配到表单上的文本框时遇到问题。代码运行时不会抛出错误,但没有数据/值传递给文本框,它们保持空白。以下是我的代码:

accepts_nested_attributes_for :bs, reject_if: proc { |attr| attr['bar'].blank? }

1 个答案:

答案 0 :(得分:0)

尝试使用Io.StreamReader,而无需NumFields

Imports System.IO
Public Class ReadingEmployeeData
    ' Declare filename
    Dim FileName As String
    Private Sub NextButton_Click(sender As Object, e As EventArgs) Handles NextButton.Click


        ' Declare variables
        Dim FileStream As StreamReader
        Dim Count As Integer


        Try
            ' Open file
            Using sr As New Io.StreamReader(FileName)

            ' Read the data

                FirstText.Text = sr.ReadLine()
                MiddleText.Text = sr.ReadLine()
                LastText.Text = sr.ReadLine()
                NumberText.Text = sr.ReadLine()
                DepartmentText.Text = sr.ReadLine()
                PhoneText.Text = sr.ReadLine()
                ExtText.Text = sr.ReadLine()
                EmailText.Text = sr.ReadLine()

                sr.Close()

            End Using

        Catch ex As Exception

           MessageBox.Show("That file can not be opened.")

        End Try
    End Sub

    Private Sub ReadingEmployeeData_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Get the filename from user
        FileName = InputBox("Please enter the name of the file")
    End Sub

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub
End Class