我正在尝试将文本文件中的文本放入文本框中,但代码执行后文本框仍为空白。我怎样才能解决这个问题?
Dim fileno1 As Integer = FreeFile()
FileOpen(fileno1, "C:\Users\main computer\Desktop\vb test\gyn-obs-D.txt", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Dim y As Boolean = 0
Dim c = 0
TextBox1.Text = "1"
Do While Not EOF(fileno1)
c += 1
Dim txt As String = LineInput(fileno1)
Debug.WriteLine(txt)
Dim inputString As String = txt
TextBox1.Text = txt
If c = 40 Then
y = 1
Exit Do
End If
write1(inputString, y)
Loop
FileClose(fileno1)
编辑:我添加了这个类,但仍然有问题
' 当然接下来的两个在顶部 Imports System Imports System.IO
Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
' The using statement also closes the StreamReader.
Using sr As New StreamReader("TestFile.txt")
Dim line As String
' Read and display lines from the file until the end of
' the file is reached.
Do
line = sr.ReadLine()
If Not (line Is Nothing) Then
Console.WriteLine(line)
End If
textbox1.text=line
Loop Until line Is Nothing
End Using
Catch e As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(e.Message)
End Try
End Sub
End Class