Я пытаюсь разместить текст из текстового файла в текстовом поле, но текстовое поле остается пустым после выполнения кода. Как я могу это исправить?Загрузка текста из файла в текстовое поле
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
Что это за «EOF (fileno1)»? –
Конец файла, @FabianBigler. –
@ DaveH cheers :) –