Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear Friends,
How do we read text file(ASCII format) line by line in VB. After the entire file is read, then how do we delete the file.Pls Help
Thanx
Anna

Hello Anna,
this is one way in which you can read a file but not line by line.
private sub command_click()
Dim fso,f
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.opentextfile(FrmChatForum.ComOpen.FileName, ForReading)
text1.Text = f.read(1000000)
end subnote that the set fso = createobject("Scripting.filesystemobject") should all be on one line.
NOW my fave bit to delete a file you use the kill key word eg
Kill("C:\windows\desktop\a.txt")
this will delete the a.txt file on desktopif you want to delete a file in you current directory ie in the directory in which yoor vb code is then you may do so thus
kill(app.path & "\a.txt")
to read a file line by line you need to use the lineinput method.
If it works let me know ill try finding a way to read line by line.
Have a nice day

woops one thing the
FrmChatForum.ComOpen.FileName
should actually be the path of the file you are trying to read
eg:
("C:\windows\desktop\a.txt",ForReading)
Sori

ok ive found my line input code, the thing is the above code may be used to read the entire file into one text box line input can be used to read each line into Different text boxes.
Here how
''''CODE''''
Dim timepstring As String
Dim TheIndex As IntegerPrivate Sub form_load()
TheIndex = 0
End SubPrivate Sub Command1_Click()
TheIndex = 0
Open ("C:\windows\desktop\a.txt") For Input As #1
Do Until EOF(1)
Line Input #1, Tempstring
Text1(TheIndex).Text = Text1(TheIndex).Text & vbCrLf & Tempstring
TheIndex = TheIndex + 1
LoopClose #1
End Sub'''''END''''
alturnetively you can remove the Theindex variable to read the text into one textbox
hope the above examples help

![]() |
ASP without session varia...
|
excel...if or vlookup?
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |