Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading data from a text file

Status
Not open for further replies.

Hawkide

Technical User
Oct 8, 2003
159
US
Excel 97

How do I read a single character from a text file?

How can I loop through the text file putting each character into a different cell?

I am opening the file using:

Open "C:\Temp\Test.txt" For Input As #1
 
Look up the Line Input function.

Don't know if it is supported in Excel, but it's in proper VB.

Try asking this in an Excel forum if you don't have any joy here...

mmilan
 
I am asking because the Help files are not installed on this piece of #$%^computer they have me working on here. Otherwise, I would gladly use Excel's help... When I use:

Input (#1, Text)

Text contains the entire line (not just one character). Since I don't have the help files I am struggling with the syntax. TIA
 
Hawkide

The easiest way to do it (i don't know the Excel vba for putting text in a cell so bear with me)

Open "c:\Temp\Test.txt" For Input As #1

Do While Not EOF(1)

Line Input #1, StrFileLine

For n = 1 to len(StrFileLine)

singlecharacter = mid(StrFileLine,n,1)

'DUMP SINGLECHARACTER In CELL

Next n

Loop


Hope It Helps

Mike
 
Thanks, that is a good solution. I'll probably use that, but does anybody know if you can do single character reads from a text file?
 
Private Sub Command1_Click()
Dim InputData As String
Open "C:\Temp\Test.txt" For Input As #1
Do Until EOF(1)
InputData = Input(1, #1)
MsgBox InputData
Loop
Close #1
End Sub

Swi
 
That's what I was looking for...Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top