Reputation: 11
How can we read the text file character by character using VB script
Upvotes: 0
Views: 2933
Reputation: 2655
To set the file path and open the text file..
fileName = "D:\Project\ABC\vbfile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(fileName)
Now to read it line by line, use below code
Do Until f.AtEndOfStream
WScript.Echo f.ReadLine
Loop
In order to read it character by character use this code
Do Until objFile.AtEndOfStream
strCharacters = f.Read(1)
Wscript.Echo strCharacters
Loop
Upvotes: 0
Reputation: 15780
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\File.txt", 1)
Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)
Wscript.Echo strCharacters
Loop
Upvotes: 2