Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: phvckmeh on October 22, 2004, 07:00 PM

Title: Saving a RTB as HTML?
Post by: phvckmeh on October 22, 2004, 07:00 PM
How would i save a Rich text box's contents as an HTML file?
Title: Re: Saving a RTB as HTML?
Post by: Networks on October 22, 2004, 07:27 PM
I'd like to know this as well, while preserving RTB colors as well!
Title: Re: Saving a RTB as HTML?
Post by: Grok on October 22, 2004, 10:05 PM
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.
Title: Re: Saving a RTB as HTML?
Post by: ______ on October 23, 2004, 04:04 PM
I would like to know how as well.
Title: Re: Saving a RTB as HTML?
Post by: LivedKrad on October 23, 2004, 08:51 PM
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
Title: Re: Saving a RTB as HTML?
Post by: LivedKrad on October 23, 2004, 09:03 PM
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.)
Title: Re: Saving a RTB as HTML?
Post by: Newby on October 23, 2004, 09:10 PM
Wow. Glad you aren't posting here, nobody likes an asshole. :)

EDIT -- Google yielded this (http://www.developer.com/net/vb/article.php/10926_1576561_3). Sorry phvckmeh, don't let the door hit you in the ass on your way out.
Title: Re: Saving a RTB as HTML?
Post by: Networks on October 24, 2004, 12:00 AM
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.
Title: Re: Saving a RTB as HTML?
Post by: Networks on October 24, 2004, 12:11 AM

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?
Title: Re: Saving a RTB as HTML?
Post by: LivedKrad on October 24, 2004, 02:10 AM
Ehh, I provided the correct logic. :P
Title: Re: Saving a RTB as HTML?
Post by: Hdx on October 24, 2004, 06:13 AM
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)~-~
Title: Re: Saving a RTB as HTML?
Post by: phvckmeh on October 24, 2004, 09:25 AM
EDIT: Na i think ill remove it and make you fuckers sweat.
Title: Re: Saving a RTB as HTML?
Post by: 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.
Title: Re: Saving a RTB as HTML?
Post by: MyndFyre on October 24, 2004, 05:18 PM
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.
Title: Re: Saving a RTB as HTML?
Post by: phvckmeh on October 25, 2004, 06:26 PM
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.
Title: Re: Saving a RTB as HTML?
Post by: Dyndrilliac on October 25, 2004, 06:57 PM
Aren't you the same dipshit that made countless "I will pay for a bot source code" topics?
Title: Re: Saving a RTB as HTML?
Post by: Stealth on October 25, 2004, 08:24 PM
Quote from: phvckmeh on October 25, 2004, 06:26 PM

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, it is attracted to other websites of the same gender?

Quoteso im not going to be posting here ever again. Too many dumshits running around.

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

Fact of the matter is that your attitude is terrible. Good riddance.
Title: Re: Saving a RTB as HTML?
Post by: Warrior on October 25, 2004, 09:00 PM
Quote from: Stealth on October 25, 2004, 08:24 PM
Quote from: phvckmeh on October 25, 2004, 06:26 PM

Anyways this site is completly homosexual

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

LMAO!
Title: Re: Saving a RTB as HTML?
Post by: LivedKrad on October 26, 2004, 12:16 PM
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?
Title: Re: Saving a RTB as HTML?
Post by: DOOM on October 30, 2004, 05:55 PM
Quote
Anyways this site is completly homosexual so im not going to be posting here ever again. Too many dumshits running around.

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.
Title: Re: Saving a RTB as HTML?
Post by: MyndFyre on October 30, 2004, 08:46 PM
Who are you, DOOM?
Title: Re: Saving a RTB as HTML?
Post by: LivedKrad on October 30, 2004, 09:02 PM
Who are you MyndFyre! :p
Title: Re: Saving a RTB as HTML?
Post by: Warrior on October 30, 2004, 09:27 PM
Who are you War?
Title: Re: Saving a RTB as HTML?
Post by: DOOM on October 31, 2004, 12:51 AM
Quote from: MyndFyre on October 30, 2004, 08:46 PM
Who are you, DOOM?

I'm not quite sure how to answer that question.  Anything specific you want to know?  :P