我有文件类型 .txt(文本文件),它有多行,我有这些图片
我想让程序生成虚假信息
意思是:当某个点击生成按钮时,它已从文本文件准备好并在 Visual Basic 中填充文本框
生成按钮上的每次点击(按下)都会使程序从文本文件(.txt)中生成新信息
我尝试了很多方法:
代码:
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt")
代码:
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt", _
System.Text.Encoding.UTF32)
和这个
代码:
Dim oFile as System****.File
Dim oRead as System****.StreamReader
oRead = oFile.OpenText(“C:\test.txt”)
和这个
代码:
Dim FILE_NAME As String = "C:\Users\user\Desktop\test.txt"
Dim objReader As New System.I--O.StreamReader(FILE_NAME)
TextBox1.Text = objReader.ReadToEnd
代码:
' Form Load :
Dim text As String = MsgBox("text you want to make the form remember it.")
Or new Sub :
Code:
Private Sub Text
text
Code:
' Button Click :
Text()
代码:
Dim path As String = "THE FILE PATH" 'The file path
Dim reader As New IO.StreamReader(path)
Dim lineIndex As Integer = 2 ' The index of the line that you want to read
For i As Integer = 0 To lineIndex - 1
reader.ReadLine()
Next
TextBox1.Text = reader.ReadLine
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ReadLineFromTxt("THE TXT FILE PATH", 0) '0 is the line index
End Sub
Public Shared Function ReadLineFromTxt(ByVal path As String, ByVal lineIndex As Integer) As String
Dim reader As New IO.StreamReader(path)
For I As Integer = 0 To lineIndex - 1
reader.ReadLine()
Next
Return reader.ReadLine()
End Function
End Class
这些方法来自这四个成员: http ://www.mpgh.net/forum/33-visual-basic-programming/693165-help-how-can-i-generate-text-txt-file-textbox-when -button-click-2.html
如果这些方法有效,请告诉我如何以最佳方式使用它
我有 Visual Studio 2012 并更新了 1
恕我直言