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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output to an HTML file

Status
Not open for further replies.

felicitea

Programmer
Jun 13, 2002
9
US
I have a VB6 application that logs values to a text file. I want to log to an HTML file instead. This file can be opened and viewed by the user at any time during the running of the application. Additional items may need to be written to the file after it is viewed so these lines would need to be inserted into the file prior to the </body> and </HTML> tags. Is there any way to do this? Thanks.
 
This will do what I think you are trying to do. First, you should start with a file named logdemo.html that resides in the same folder as your project. It should look like this:
Code:
<HTML><BODY></BODY></HTML>
Be sure not to use any spaces or carriage returns!
Now, use the following code to write the values to the file. Of course, the code will have to be adapted to your particular situation, but this should give you the idea.

Code:
Private Sub cmdLog_Click()
Dim strHeader As String
Dim strValue As String
Dim strFooter As String
Dim strFile [As String

'Reads contents of file into strHeader
Open App.Path & &quot;\logdemo.html&quot; For Input As #1
Input #1, strHeader
Close #1

'Strips the footer from strHeader
strHeader = Left(strHeader, InStr(strHeader, &quot;</BODY>&quot;) - 1)

'Gets value entered by user.
'The <p> puts blank line between each entry.
strValue = txtValue.Text & &quot;<p>&quot;

'Rebuilds the footer
strFooter = &quot;</BODY></HTML>&quot;

'Builds output string
strFile = strHeader & strValue & strFooter

'Overwrites .html file
Open App.Path & &quot;\logdemo.html&quot; For Output As #1
Print #1, strFile
Close #1

End Sub
Be sure to use the Print method to output your data to the file. The Write method will insert quotation marks in the file, which you don't want!
 
I think this will help me. Thanks for the input. Is there any way to make a template html file for output so that not everything (headers, etc.) has to be written each time? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top