Computing.Net > Forums > Programming > vb read and write file

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

vb read and write file

Reply to Message Icon

Original Message
Name: gorf
Date: June 1, 2003 at 18:05:37 Pacific
Subject: vb read and write file
OS: winxp
CPU/Ram: 2600+ / 512mb pc3200
Comment:

anyone know how to read a file in vb
like read file.txt text form file go to text1.text

and write to file


Report Offensive Message For Removal


Response Number 1
Name: micah
Date: June 2, 2003 at 16:06:44 Pacific
Reply: (edit)

I do.


Report Offensive Follow Up For Removal

Response Number 2
Name: micah
Date: June 2, 2003 at 20:36:07 Pacific
Reply: (edit)

Dim FileData As String
Open "c:\file.txt" For Binary Access Read As #1
FileData = Space(LOF(1))
Get 1, , FileData
Close #1

That'll read.

Open "c:\text1.txt" For Binary Access Write As #1
Put 1, , FileData
Close #1

That'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 #1

Easy enough?


Report Offensive Follow Up For Removal

Response Number 3
Name: gorf
Date: June 3, 2003 at 11:42:48 Pacific
Reply: (edit)

ummmm..... im readin it learn it


Report Offensive Follow Up For Removal

Response Number 4
Name: gorf
Date: June 3, 2003 at 12:00:12 Pacific
Reply: (edit)

hows about in the dame dir as the app?


Report Offensive Follow Up For Removal

Response Number 5
Name: Chi Happens
Date: June 22, 2003 at 05:46:13 Pacific
Reply: (edit)

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"


Report Offensive Follow Up For Removal


Response Number 6
Name: Carlos Eugênio
Date: July 17, 2003 at 10:31:15 Pacific
Reply: (edit)

I'm doing like you said, but when I execute the following error appears:

Runtime Error: 75
Path/File access error

Please, answer me on my email. Thanks!


Report Offensive Follow Up For Removal

Response Number 7
Name: Carlos Eugênio
Date: July 17, 2003 at 10:41:56 Pacific
Reply: (edit)

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.



Report Offensive Follow Up For Removal






Post Locked

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


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software