Hello
Can anyone help me to read Each Line in Textbox1 of a text file.
Have 2 command buttons cmdReadNextLine and cmdReadPreviousLine and Textbox1.Multiline = False
By Pressing cmdReadNextLine i would like to read the single Next Line of Text file in Textbox1
and By Pressing cmdReadPreviousLine i would like to read the previous Line of Text file in Textbox1.
Even if there is blank line in Text file the Textbox should display as is or Blank
I was only able to load the text file with below Code and it displayed the last line of the text file
Any ideas how the First line could be displayed in Textbox1.text and pressing above respective command buttons to do the necessary actions
Require your help for coding for command buttons to get the desired results
Thank you
SamD
196
Can anyone help me to read Each Line in Textbox1 of a text file.
Have 2 command buttons cmdReadNextLine and cmdReadPreviousLine and Textbox1.Multiline = False
By Pressing cmdReadNextLine i would like to read the single Next Line of Text file in Textbox1
and By Pressing cmdReadPreviousLine i would like to read the previous Line of Text file in Textbox1.
Even if there is blank line in Text file the Textbox should display as is or Blank
I was only able to load the text file with below Code and it displayed the last line of the text file
Any ideas how the First line could be displayed in Textbox1.text and pressing above respective command buttons to do the necessary actions
Require your help for coding for command buttons to get the desired results
VBA Code:
Private Sub fsoMethod_ReadEachLine()
Dim myFilePath As String, strFileData As String, eachLine As String
Dim fso As Object, txtDataObj As Object, lCount As Long
Set fso = CreateObject("Scripting.FileSystemObject")
myFilePath = "C:\ABC\1.txt"
Set txtDataObj = fso.OpenTextFile(myFilePath, 1)
While Not txtDataObj.AtEndOfStream
eachLine = txtDataObj.readline
TextBox1.Text = eachLine
Wend
txtDataObj.Close
Set fso = Nothing
End Sub
SamD
196