• Welcome to Valhalla Legends Archive.
 

Saving a RTB as HTML?

Started by phvckmeh, October 22, 2004, 07:00 PM

Previous topic - Next topic

phvckmeh

How would i save a Rich text box's contents as an HTML file?

Networks

I'd like to know this as well, while preserving RTB colors as well!

Grok

Quote from: phvckmeh on October 22, 2004, 08:05 PM
i got it, if anyone needs it drop me a message at www.clancybr.com

it preserves txt color and font, and size ETC

Um, no, if you're going to use this forum for the question, use it for the answer too.  Other people may have the same question.

______

I would like to know how as well.

LivedKrad

I'm just ball-parking here, but wouldn't the RTB's rich formatting abilities be converted to format characters when put into a regular text box? Maybe you could take these special characters and give them the colors you need when outputting to an HTML file. Again, I don't know if this is a way to do it or not, just something I thought up. :P

LivedKrad

Then, sir, I would call you an asshole. 50kb? Provide the logic behind the operation, and pasting the entire code won't be necessary. Or, you can be a dick and *possibly* get banned and never come back. (Even if you wanted to.)

Newby

#6
Wow. Glad you aren't posting here, nobody likes an asshole. :)

EDIT -- Google yielded this. Sorry phvckmeh, don't let the door hit you in the ass on your way out.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Networks

Why does it seem like he's fucking attempting his gay fucking ass site? How about you just remove his fucking posts since obviously none of his crap shit is helping anyone.

Networks


Public Function ConvertToHTML(ByVal Box As RichTextBox) _
               As String
   ' Takes a RichTextBox control and returns a
   ' simple HTML-formatted version of its contents
   Dim strHTML As String
   Dim strColour As String
   Dim blnBold As Boolean
   Dim blnItalic As Boolean
   Dim strFont As String
   Dim shtSize As Short
   Dim lngOriginalStart As Long
   Dim lngOriginalLength As Long
   Dim intCount As Integer
   ' If nothing in the box, exit
   If Box.Text.Length = 0 Then Exit Function
   ' Store original selections, then select first character
   lngOriginalStart = 0
   lngOriginalLength = Box.TextLength
   Box.Select(0, 1)
   ' Add HTML header
   strHTML = "<html>"
   ' Set up initial parameters
   strColour = Box.SelectionColor.ToKnownColor.ToString
   blnBold = Box.SelectionFont.Bold
   blnItalic = Box.SelectionFont.Italic
   strFont = Box.SelectionFont.FontFamily.Name
   shtSize = Box.SelectionFont.Size
   ' Include first 'style' parameters in the HTML
   strHTML = strHTML & "<span style=""font-family: " & strFont & _
     "; font-size: " & shtSize & "pt; color: " _
                     & strColour & """>"
   ' Include bold tag, if required
   If blnBold = True Then
       strHTML = strHTML & "<b>"
   End If
   ' Include italic tag, if required
   If blnItalic = True Then
       strHTML = strHTML & "<i>"
   End If
   ' Finally, add our first character
   strHTML = strHTML & Box.Text.Substring(0, 1)
   ' Loop around all remaining characters
   For intCount = 2 To Box.Text.Length
       ' Select current character
       Box.Select(intCount - 1, 1)
       ' If this is a line break, add HTML tag
       If Box.Text.Substring(intCount - 1, 1) = _
              Convert.ToChar(10) Then
           strHTML = strHTML & "<br>"
       End If
       ' Check/implement any changes in style
       If Box.SelectionColor.ToKnownColor.ToString <> _
          strColour _ Or Box.SelectionFont.FontFamily.Name _
          <> strFont Or _ Box.SelectionFont.Size <> shtSize _
          Then
           strHTML = strHTML & "</span><span style=""font-family: " _
             & Box.SelectionFont.FontFamily.Name & _
             "; font-size: " & Box.SelectionFont.Size & _
             "pt; color: " & _
             Box.SelectionColor.ToKnownColor.ToString & """>"
       End If
       ' Check for bold changes
       If Box.SelectionFont.Bold <> blnBold Then
           If Box.SelectionFont.Bold = False Then
               strHTML = strHTML & "</b>"
           Else
               strHTML = strthml & "<b>"
           End If
       End If
       ' Check for italic changes
       If Box.SelectionFont.Italic <> blnItalic Then
           If Box.SelectionFont.Italic = False Then
               strHTML = strHTML & "</i>"
           Else
               strHTML = strHTML & "<i>"
           End If
       End If
       ' Add the actual character
       strHTML = strHTML & Mid(Box.Text, intCount, 1)
       ' Update variables with current style
       strColour = Box.SelectionColor.ToKnownColor.ToString
       blnBold = Box.SelectionFont.Bold
      blnItalic = Box.SelectionFont.Italic
       strFont = Box.SelectionFont.FontFamily.Name
       shtSize = Box.SelectionFont.Size
   Next
   ' Close off any open bold/italic tags
   If blnBold = True Then strHTML = strHTML + ""
   If blnItalic = True Then strHTML = strHTML + ""
   ' Terminate outstanding HTML tags
   strHTML = strHTML & "</span></html>"
   ' Restore original RichTextBox selection
   Box.Select(lngOriginalStart, lngOriginalLength)
   ' Return HTML
   ConvertToHTML = strHTML
End Function


This was converted partially from .NET, can anyone fix the Box.Select and Box.SelectionColor.ToKnownColor.ToString to VB6 compliant please?

LivedKrad

Ehh, I provided the correct logic. :P

Hdx

Public Function HTML() As String
With Bots(1).txtChat
    Dim HTMLCode As String
    Dim Color As String
    Dim Size As String
    Dim Font As String
    Dim Bold As Boolean
    Dim Itlz As Boolean
    Dim Pos As Integer
    Dim SameText As String
Top:
    .SelStart = Pos
    .SelLength = 1
    Size = .SelFontSize
    Font = .SelFontName
    Color = .SelColor
    HTMLCode = HTMLCode & "<font size=" & Chr(32) & Size & Chr(32) & " face=" & _
                            Chr(32) & Font & Chr(32) & " color=" & Chr(32) & Color _
                            & Chr(32) & ">"
        SameText = vbNullString
    For T = Pos To InStr(.Text, vbCrLf)
        .SelStart = Pos
        .SelLength = 1
        If .SelColor = Color Then
            If .SelFontSize = Size Then
                If .SelFontName = Font Then
                    SameText = SameText & _
                                IIf(.SelBold And Bold = False, "<B>", "") & _
                                IIf(.SelBold = False And Bold, "</B>", "") & _
                                IIf(.SelItalic And Itlz = False, "<I>", "") & _
                                IIf(.SelItalic = False And Itlz, "</I>", "") & _
                                .SelText
                Else
                    HTMLCode = HTMLCode & SameText & "</font>"
                    GoTo Top
                End If
            Else
                HTMLCode = HTMLCode & SameText & "</font>"
                GoTo Top
            End If
        Else
            HTMLCode = HTMLCode & SameText & "</font>"
            GoTo Top
        End If
        Pos = Pos + 1
    Next T
End With
HTML = HTMLCode & SameText & "</font>"
End Function

Ok, this takes the 1st line of a rtb.. might be usefull to someone.. I've tested iit cuz i made it :P so ya works for me.
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

phvckmeh

EDIT: Na i think ill remove it and make you fuckers sweat.

Stealth

Quote from: phvckmeh on October 24, 2004, 09:25 AM
EDIT: Na i think ill remove it and make you fuckers sweat.

This post was never edited. You're just being a douche.
- Stealth
Author of StealthBot

MyndFyre

Quote from: phvckmeh on October 24, 2004, 09:25 AM
EDIT: Na i think ill remove it and make you fuckers sweat.

Ya know what's even cooler?  My RTB to HTML, Plaintext, and YaBBCode converter.  And that's only about 24kb, plus 20kb for the styles page definition.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

phvckmeh

Quote from: Stealth on October 24, 2004, 04:54 PM
Quote from: phvckmeh on October 24, 2004, 09:25 AM
EDIT: Na i think ill remove it and make you fuckers sweat.

This post was never edited. You're just being a douche.

I posted it and then about ~30 seconds later i removed it, hence there was no "this post was edited" tag. Dumfuck

Anyways this site is completly homosexual so im not going to be posting here ever again. Too many dumshits running around.