PDA

View Full Version : How to read from a text file



abdulaziz
07-22-2015, 05:33 AM
I am using "FileWrite" function to write to text file. But don't know how to read from text file. I need to read from a text file like 5th line or 2nd line or 12​th line.
Please anyone guide me.
regards

Rawan-HS
07-22-2015, 09:25 AM
Dear Abdulaziz :)


the bellow code use to read line by line from the file try it




Public Sub main()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\test.txt", ForReading)
Const ForReading = 1
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
msgBox arrFileLines(i)
i = i + 1
Loop
objFile.Close
End Sub

Rawan-HS
07-22-2015, 01:58 PM
Dear Abdulaziz

try this code for a specific line number


Dim fileName
fileName = "C:\VertexWorld.txt"
msgbox GetEntry (Cstr(fileName),L)
'L means the line number