01-21-2008, 09:25 AM
I have a web page i made that i need to append more html code
to later and i'm having a hard time doing it.
This isnt a full blown web page. Just something a web browser control
can open in a vb6 form.
The tags are few:
Existing text is already here
I'd like to append extra text here
I know i have to first find the </Body> tag but how can i place the
extra text just before that tag?
I'm opening the htm file using append but after that, i'm lost.
Anyone got any idea's?
01-21-2008, 09:28 AM
Heres a simple idea. Replace the tag with the new data and the tag.
If you are using the web browser control then it should have a property for this. Might be something like document.body?
01-21-2008, 10:12 AM
Just leave off the </BODY> and </HTML> close-tags entirely. People do this all the time.
This is what quirks-mode is all about, also why you can't parse HTML as XML.
01-21-2008, 01:10 PM
I'm just using a textbox to edit html code.
My problem is with the Replace function. I'm trying out the masters
idea about replacing the body tag with different text and then adding
the tag back to it but i'm getting odd results doing it that way. The
text that i'm appending is at the top of the code as well as where it
is suppose to be and i cant figure it out.
Here's the code i use to put html code in a textbox
Dim strBuff As String
' Load File in to text box
Open ChatPath & "Append.HTM" For Binary As #1
strBuff = Space(LOF(1))
Get #1, , strBuff
Text1.Text = strBuff
That part is fine
Here is where i get the tags:
Dim AreaToFind As String
Dim StringToFind As String
' Get the tags
AreaToFind = Right(Text1.Text, 16) ' Gets </body></html>
StringToFind = Left(AreaToFind, 7) ' Gets </body>
That part seems fine also
Here is where the trouble lies
Dim tempString As String
' Add new text to body of html file
tempString = Replace(Text1.Text, StringToFind , "<br>My name is Micky Mouse" & vbCrLf & StringToFind )
Text1.Text = tempString
Here's the HTML code i use
<p align="center"><font size="5" face="Comic Sans MS"
<br>My name is Goofy
<br>My name is Donald Duck
Am i using the replace function wrong?
01-21-2008, 01:33 PM
Its simpler than that. You dont need to check for a HTML tag.
dim strHTML as string
dim strNewText as string
'Get the html value
strnewtext = "This is some random text"
strhtml = replace(strhtml,"</body>",strnewtext & "</body>",vbstringcompare)
Where the body tag was you should now have your extra stuff and the body tag again. This should work even if you have a </html> tag on the end with no extra work.
Leaving the tags off could work i suppose but im sure the web browser control is very close to IE itself and IE has added tags in automatically when ive missed them out before.
I like everything to be w3c compliant too and as forwards compatible as possible. Im not sure if you can remove those tags in plain HTML but you definately cant in XHTML
01-21-2008, 01:40 PM
I think i got it now. I was trying to save using the wrong
file open operation. I was trying to re-open the file in binary
when i should have been using output to create a new file
instead of reusing the old one.
Thanks for the help
01-21-2008, 01:44 PM
Ahh, ic. Make sure to use vbtextcompare though because in normal HTML you are allowed upper or mixed case tags. vbtextcompare performs a case insensitive search