Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
anyone know how to read a file in vb
like read file.txt text form file go to text1.textand write to file

Dim FileData As String
Open "c:\file.txt" For Binary Access Read As #1
FileData = Space(LOF(1))
Get 1, , FileData
Close #1That'll read.
Open "c:\text1.txt" For Binary Access Write As #1
Put 1, , FileData
Close #1That'll write...
You can also read and write to the same file at the same time.
Dim FileData As String
Open "c:\blabla.txt" For Binary Access Read Write As #1
FileData = Space(LOF(1))
Get 1, , FileData
Put 1, , "stuff" & FileData
Close #1Easy enough?

Well, not certain about the sex of the object but:
App.Path
works for the current path.
you might need to append a "\" before your file name tho.
like FileSpec = App.Path & "\myfile.txt"

I'm doing like you said, but when I execute the following error appears:
Runtime Error: 75
Path/File access errorPlease, answer me on my email. Thanks!

In fact, I’d like to read the contents of a binary file, find an specific string in it and finally change this string with another one I want, writing it on the same file, keeping the binary aspect and not damaging the file. As we do using hexdecimal editors.
How can I do it?
Please, answer me on my email.
Thanks.

![]() |
Inline functions
|
hugging the Processor
|

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