|
-
Dec 4th, 2000, 08:01 PM
#1
Thread Starter
Addicted Member
Hello,
How do you open a text file for editing?
Example.
I open a text file that has 3 lines.
textfile1
Hello this is vb world.
How are you today.
Wow im bored.
- end of file
Now how would i go about inserting an extra line w. out erasing the rest.
Thanks.
-
Dec 4th, 2000, 08:16 PM
#2
To open:
Dim strLine$
Open "FILE" For Input As #1
Do While Not EOF(1)
Line Input #1, strLine$
Text1.text = Text1.text & strLine$
Loop
Close #1
To save:
Open "FILE" For Output As #1
Print #1, Text1.text
Close #1
-
Dec 4th, 2000, 08:31 PM
#3
Thread Starter
Addicted Member
Im just trying to edit.
If i open a file and use it as output and then
use the print command filenumber and text, it will erase
all other previous text in the file.
I am just wanting to add to it.
-
Dec 4th, 2000, 08:38 PM
#4
PowerPoster
use the open "FILE" for append as #1
example:
Code:
Dim strLine$
Open "FILE" For Append As #1
Do While Not EOF(1)
Line Input #1, strLine$
Text1.text = Text1.text & strLine$
Loop
Close #1
I think that will work. If now, just go to Kedaman's webpage, he has a good tutorial all about file opening and editing. http://www.geocities.com/kedasu/kedamans_file.htm
Check out the rest of his site too, it's got neat stuff on it.
-
Dec 4th, 2000, 08:41 PM
#5
_______
<?>
You need to open for Append to add to the file.
Output will overwrite the entire file.
Matthew knows this, it's a slip of the typo.
Code:
Option Explicit
Private Sub Form_Load()
'use a multiline text box with scrollbars
Dim i As Integer
Dim myVar As String
Text1 = ""
Open "C:\my documents\myfile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, myVar
If i = 0 Then
Text1 = myVar & vbNewLine
Else
Text1 = Text1 & myVar & vbNewLine
End If
i = i + 1
Loop
Close
End Sub
Private Sub Command1_Click()
'once you have made your changes in the text box
'ie added a fourth line
Open "C:\my documents\myfile.txt" For Append As #1
Print #1, Text2.Text
Close #1
'refresh
Call Form_Load
Text2 = ""
Text2.SetFocus
End Sub
[/code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 4th, 2000, 08:54 PM
#6
Thread Starter
Addicted Member
Okay i got it finally 
Thanks guys...
-
Dec 4th, 2000, 09:12 PM
#7
You are absolutely right Wayne.
I had Append at first. Than I changed it, than I said to myself, that's not right, than my brother came in and needed help studying for a test and I posted the reply and got distracted and all. Anyways, always go with what you gut feeling tells you. (from Who Wants to be a Millionaire?)
We all make mistake, no ones perfect.
Look at what Wayne does sometimes...
[code]
MyCode
'and then he puts:
[code]
again and forgets to close your opened code tag ([/code]).
That annoys me the hell out of me, hehe, but I learn to deal with it .
-
Dec 4th, 2000, 09:25 PM
#8
_______
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|