title: how to read from text file to textbox in visual basic 1 line every hit on button
body: <p>I have files type .txt (Text File) and it's have multiple line and i have these pictures </p>
  
  <p>i want to make program generate fake information</p>
  
  <p>Mean: when some one hit generate button it's ready from text file and fill textbox in visual basic</p>
  
  <p>every hit(press) on Generate Button make program generate new information from text files (.txt)</p>
  
  <p>i tried a lot ways:</p>
  
  <p>Code:</p>
  
  <pre><code>Dim fileReader As String
  fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt")
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>Dim fileReader As String
  fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt", _
     System.Text.Encoding.UTF32)
  </code></pre>
  
  <p>and this</p>
  
  <p>Code:</p>
  
  <pre><code> Dim oFile as System****.File
  Dim oRead as System****.StreamReader
  oRead = oFile.OpenText(“C:\test.txt”)
  </code></pre>
  
  <p>and this</p>
  
  <p>Code:</p>
  
  <pre><code> 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
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>' 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()
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>These ways take from members in this fourm:
   <a href="http://www.mpgh.net/forum/33-visual-basic-programming/693165-help-how-can-i-generate-text-txt-file-textbox-when-button-click-2.html" rel="nofollow">http://www.mpgh.net/forum/33-visual-basic-programming/693165-help-how-can-i-generate-text-txt-file-textbox-when-button-click-2.html</a></p>
  
  <p>if are these ways working please tell me how to use it in best way</p>
  
  <p>i have Visual studio 2012 and updated 1</p>
  
  <p>With all due respect</p>