By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,575 Members | 3,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,575 IT Pros & Developers. It's quick & easy.

Changing data in text file using VB 6.0

P: 7
Hello there,

I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
Jun 8 '07 #1
Share this Question
Share on Google+
4 Replies


Dököll
Expert 100+
P: 2,364
Hello there,

I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
Hello there, varsha desai!

Use the replace command to changes things 'round:
Jun 8 '07 #2

P: 14
Hello there,

I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
Hi
This is my first reply
This way is one of old ways that VB6.0 got it from QBasic
I think the easy way is:
Open:
Expand|Select|Wrap|Line Numbers
  1.     Dim s as String
  2.     Open "C:\test.txt" For input As #1
  3.         Input #1, s
  4.     Close #1
Save:
Expand|Select|Wrap|Line Numbers
  1.     Open "C:\test.txt" For output As #1
  2.         Print #1, "Test"
  3.         Write #1, "Test"
  4.     Close #1
Append:
Expand|Select|Wrap|Line Numbers
  1.     Open "C:\test.txt" For Append As #1
  2.         Print #1, "Test"
  3.         Write #1, "Test"
  4.     Close #1
these are for Text file but if you wanna use it for a binary file:
1. use "Binary" instead of "Output" or "Input" or "Append"
2. use "Get" and "Put" instead of "Input" and "Print" or "Write"

.:!M!LDEREMi:.
Jun 8 '07 #3

P: 14
Hello there, varsha desai!

Use the replace command to changes things 'round:
Hi
If you use RichTextBox there is a command that load the file in the easiest way and also a command for Replacement but if you wanna do it in the best way don't use it. The best way is opening file in Binary mode and get the data from file directly... in this way you won't need ActiveX of rich text box.

Also this way is the best way in VB.NET faster and easier than VB6.
Jun 8 '07 #4

danp129
Expert 100+
P: 321
If opening more than one file at a time you need to find a free file handle to use

Expand|Select|Wrap|Line Numbers
  1. Dim s as String, lngFile as long
  2. lngFile=FreeFile
  3. Open "C:\test.txt" For input As #lngFile
  4. Input #lngFile, s
  5. Close #lngFile
Jun 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.