Print the content of the text file


How to print line by line of text file content?

Here is my example. I have one text file called myprofile with 3 line as follow:

line 1 : myname
line 2 : myage
line 3 : mydob

I want the program to read this myprofile.txt and assign line by line to a variable until end of file. Then print out this text file content.

Help please.

Who is Participating?
setiawanConnect With a Mentor Commented:
Sub CopyToPrinter()
  Open "textfile.txt" For Binary As 1
  Open "LPT1:" For Binary As 2
  Do Until EOF(1)
    Get #1, , a
    Put #2, , a
  Close 2
  Close 1
End Sub

Dim sFileName As String
Dim sData As String
Dim iFileNum As Integer

iFileNum = FreeFile
sFileName = "C:\gwdbg32.txt"
Open sFileName For Input As iFileNum
Do Until EOF(iFileNum)
    Line Input #iFileNum, sData
    Printer.Print sData
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.