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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FSO -FileSystemObject... Reading word by word. 1

Status
Not open for further replies.

annanathan

Programmer
May 1, 2002
24
0
0
CA
Hi All,
Does anyone know how to read word by word from a file using FSO?

Another question... Is there a rewind or some similar function in FSO to go back to the line just read?

Thanks in advance.
 

Dim sChar As String
Dim sWord As String
Dim sCurrLine As String
Dim sPrevLine As String

Set f = fso_OpenTextFile(sPATHandNAME_TFINI, IOMode:=ForReading)
Do Until f.AtEndOfStream = True
sChar = f.Read(1)

If sChar = " " Then

Debug.Print sWord

sWord = vbNullString

ElseIf sChar = vbCr Then
Debug.Print sWord

sWord = vbNullString
sPrevLine = sCurrLine
sCurrLine = vbNullString
sWord = vbNullString

ElseIf sChar = vbLf Or sChar = vbCrLf Then

Else
sWord = sWord & sChar
sCurrLine = sCurrLine & sChar
End If
Loop
f.Close
Set f=Nothing
Set fso=Nothing




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top