Hi guys this is my first post on here so im sorry if its not done properly its just i have spent several hours trying to solve this problem already and I am starting to get very frustrated.

Basically I have create a basic HTML editor using visual basic 6, I have everything working with exception to opening a html file back into my Rich Text Box. I have saved to the file using showsave and am wanting to open the file using showopen. I have got the showopen code in place and it is picking up the correct file, I know this because it will let me use the filetitle as the caption of my form - my probelm is it will not copy the content back from the html file to the RTB.

I have tried many things and am getting so frustrated pleases help

Dani AI

Generated

A short, practical fix for the setup described by (saved HTML file, want the HTML source back into the RichTextBox): the VB6 RichTextBox can load plain text files directly — use its LoadFile method with the text mode (not RTF). If the CommonDialog is used, pass CommonDialog1.FileName (full path) into LoadFile and request rtfText so the control treats the file as plain text rather than RTF. (manifold.net)

Example (simple, VB6):

' show open dialog and load source into the RichTextBox as plain text
CommonDialog1.Filter = "HTML Files (*.htm;*.html)|*.htm;*.html|All Files (*.*)|*.*"
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) Then
    RichTextBox1.LoadFile CommonDialog1.FileName, rtfText
End If

If characters look garbled (non-ASCII / UTF-8 HTML), read the file with ADODB.Stream specifying the correct charset and then assign the resulting string to the RichTextBox.Text. This handles UTF-8, BOMs and other encodings that VB6 native text I/O can mishandle:

' late-bound ADO Stream (no project reference required)
Dim stm As Object, txt As String
Set stm = CreateObject("ADODB.Stream")
stm.Type = 2        ' adTypeText
stm.Charset = "utf-8"
stm.Open
stm.LoadFromFile CommonDialog1.FileName
txt = stm.ReadText
stm.Close
Set stm = Nothing
RichTextBox1.Text = txt

Two quick troubleshooting notes tied to the original posts: (1) CommonDialog1.FileTitle returns only the file name (no path) — using FileTitle where FileName is required will make LoadFile fail if the file isn’t in the current working folder. (2) The RichTextBox displays plain text or RTF, it does not render HTML; for a WYSIWYG preview the WebBrowser/MSHTML route (as mentioned by ) is the correct approach. (developerfusion.com)

Recommended Answers

All 3 Replies

Hi,

I don't know what IDE you are using but if VB You can't use the richtext control to display an html file?? and even if you used the .filename property you will get the html source of the file instead of the content. An OLE object will not work even. You will need to use a webbrowser
through adding the component "
Microsoft Internet Controls". And then call the file using the Navigate function ex: Me.WebBrowser1.Navigate "c:\temp.htm".

Hi,

I don't know what IDE you are using but if VB You can't use the richtext control to display an html file?? and even if you used the .filename property you will get the html source of the file instead of the content. An OLE object will not work even. You will need to use a webbrowser
through adding the component "
Microsoft Internet Controls". And then call the file using the Navigate function ex: Me.WebBrowser1.Navigate "c:\temp.htm".

I appreciate the reply, maybe i was not fully clear of my problem let me try again.

I have constructed a simple html editor / wysiwyg program that allows the user to preview their work in a web browser. I have already coded the browser part and the code that generates the html and the wysiwyg part. I have also managed to save the file from the editor to a .html file.

I know this is working because i can open the file using firefox and preview it. My problem comes when trying to load the source code back from that file to the program. I figured because the source code is already displayed/created in a rich text box on my source tab (similar to dreamweaver) then i should be able to take the source from the html file and load it back into the RTB to edit. I am using visual basic 6 - Sorry if my post didnt make much sense earlier I had been looking for hours and was almost sick of trying. I hope this one made more sense

no takers then?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.