Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving to a text file- Help needed badly

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hello all. Anyway, my question for you all is about writing to a specific line , or after a specific charator(s) in a text file. I am currently writing a simple html generator, and there is a text box in which you will type the body of the html file. what i am wanting to do is this: when the document is saved, the program should automaticaly write:
<html>
<head>
</head>
<title>
on the form, there will be a place to enter the title of the web page, and that entry field will place the text contained in it after the title tag, then it will place </title> after that. then the program will automatically write:
<body>
to the html file. in the text box you wil type what you want the body to say. when you save, the program will insert:
</body>
at the end of the html file.
my question is... HOW DO I DO THIS??? [sig][/sig]
 
You'll have to recreate the text file from scratch each time I think. There isn't a way to insert text in a text file without doing some copying. The algorithm for the standard way to do this looks like this:

open text_file for input
open text_file_2 for output
read lines from text_file and write them out to text_file_2 until you find the line *BEFORE* the one you want to modify.
skip over that line in text_file
write the modified line out to text_file_2
read lines from text_file and write them out to text_file_2 until eof(text_file)
close text_file, text_file_2
delete text_file
rename text_file_2 text_file




Mike
michael.j.lacey@ntlworld.com
 
You could...
[tt]
Private Sub Command1_Click()
HTMLFile$ = &quot;C:\My.HTML&quot;
If Dir(HTMLFile$) <> &quot;&quot; Then Kill HTMLFile$
ff = FreeFile
Open HTMLFile$ For Binary As #ff
Temp$ = &quot;<html>&quot; & vbCrLf & &quot;<head>&quot; & vbCrLf & &quot;</head>&quot; & vbCrLf & &quot;<title>&quot;
Temp$ = Temp$ & vbCrLf & Title.txt & vbCrLf & &quot;</title>&quot;
Temp$ = Temp$ & vbCrLf & &quot;<body>&quot; & vbCrLf & Body.txt & vbCrLf & &quot;</body>&quot; & vbCrLf
Put #ff, 1, Temp$
Close #ff
End Sub
[/tt]

Since the structure of the file is known, why bother to insert text into it? Just overwrite it.
VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top