Valhalla Legends Forums Archive | Visual Basic Programming | Saving a RTB as HTML?

AuthorMessageTime
phvckmeh
How would i save a Rich text box's contents as an HTML file?
October 23, 2004, 12:00 AM
Networks
I'd like to know this as well, while preserving RTB colors as well!
October 23, 2004, 12:27 AM
Grok
[quote author=phvckmeh link=topic=9285.msg85728#msg85728 date=1098493522]
i got it, if anyone needs it drop me a message at www.clancybr.com

it preserves txt color and font, and size ETC
[/quote]

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.
October 23, 2004, 3:05 AM
______
I would like to know how as well.
October 23, 2004, 9:04 PM
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
October 24, 2004, 1:51 AM
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.)
October 24, 2004, 2:03 AM
Newby
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.
October 24, 2004, 2:10 AM
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.
October 24, 2004, 5:00 AM
Networks
[code]
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
[/code]

This was converted partially from .NET, can anyone fix the Box.Select and Box.SelectionColor.ToKnownColor.ToString to VB6 compliant please?
October 24, 2004, 5:11 AM
LivedKrad
Ehh, I provided the correct logic. :P
October 24, 2004, 7:10 AM
HdxBmx27
[code]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[/code]
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)~-~
October 24, 2004, 11:13 AM
phvckmeh
EDIT: Na i think ill remove it and make you fuckers sweat.
October 24, 2004, 2:25 PM
Stealth
[quote author=phvckmeh link=topic=9285.msg85907#msg85907 date=1098627925]
EDIT: Na i think ill remove it and make you fuckers sweat.
[/quote]

This post was never edited. You're just being a douche.
October 24, 2004, 9:54 PM
Myndfyr
[quote author=phvckmeh link=topic=9285.msg85907#msg85907 date=1098627925]
EDIT: Na i think ill remove it and make you fuckers sweat.
[/quote]

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.
October 24, 2004, 10:18 PM
phvckmeh
[quote author=Stealth link=topic=9285.msg85957#msg85957 date=1098654849]
[quote author=phvckmeh link=topic=9285.msg85907#msg85907 date=1098627925]
EDIT: Na i think ill remove it and make you fuckers sweat.
[/quote]

This post was never edited. You're just being a douche.
[/quote]

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.
October 25, 2004, 11:26 PM
Dyndrilliac
Aren't you the same dipshit that made countless "I will pay for a bot source code" topics?
October 25, 2004, 11:57 PM
Stealth
[quote author=phvckmeh link=topic=9285.msg86118#msg86118 date=1098746809]

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[/quote]

So, it is attracted to other websites of the same gender?

[quote]so im not going to be posting here ever again. Too many dumshits running around.
[/quote]

You're aware that there's a "b" in the word "dumb"?

Fact of the matter is that your attitude is terrible. Good riddance.
October 26, 2004, 1:24 AM
Quarantine
[quote author=Stealth link=topic=9285.msg86134#msg86134 date=1098753848]
[quote author=phvckmeh link=topic=9285.msg86118#msg86118 date=1098746809]

Anyways this site is completly homosexual[/quote]

So, it is attracted to other websites of the same gender?
[/quote]

LMAO!
October 26, 2004, 2:00 AM
LivedKrad
What puzzles me is that you posted some to the degree "i be leaving u fukers so i no post here no more", on the 23rd of October. However, I see you have posted twice in a time span of 2 days following the time in which you said you would "make us sweat yo". So tell me, can it be that you are so desperate as to NEED to give a "witty" retort to something that started out as a helpful topic, or am I completely wrong?
October 26, 2004, 5:16 PM
DOOM
[quote]
Anyways this site is completly homosexual so im not going to be posting here ever again. Too many dumshits running around.
[/quote]

At least we know it is completely homosexual and no just half way homosexual (aka bisexual).  We wouldn't want this website being too much of a slut and getting it from all genders, right?  Where do websites keep their genitals anyway?  I don't recall seeing any html tags for that.

We'll all try not to lose any sleep over you not posting here again.  I did a pretty good job of it last night too.  12 hours of sleep > you.
October 30, 2004, 10:55 PM
Myndfyr
Who are you, DOOM?
October 31, 2004, 1:46 AM
LivedKrad
Who are you MyndFyre! :p
October 31, 2004, 2:02 AM
Quarantine
Who are you War?
October 31, 2004, 2:27 AM
DOOM
[quote author=MyndFyre link=topic=9285.msg86704#msg86704 date=1099187192]
Who are you, DOOM?
[/quote]

I'm not quite sure how to answer that question.  Anything specific you want to know?  :P
October 31, 2004, 5:51 AM

Search