Option Explicit
Sub RenderHTML(pic As PictureBox, html As String) ' ' Always declare variables Integers ' Dim lentext As Integer Dim html_loop_1 As Integer 'The main loop Dim html_loop_2 As Integer 'Secondary loop Dim html_pos_1 As Integer'Opening carret Dim html_pos_2 As Integer'Closing carret 'Strings Dim str_html As String 'The copy of the original HTML string Dim html_tag As String 'Stores the tag... Dim html_text As String 'Stores the text to be modified by the tags Dim cur_char As String 'Used in the loops, one char at a time 'Boolean Dim open_c As Boolean'Is it an opening carret? Dim close_c As Boolean 'Is it a closing carret? ' 'Get the length of the HTML and some other things... ' lentext = Len(html) 'The length of the HTML String str_html = html 'The copy of the original HTML String ' 'Loop though the HTML ' For html_loop_1 = 1 To lentext 'The main loop 'Find the locations of the Opening and Closing carrets html_pos_1 = InStr(str_html, "<") html_pos_2 = InStr(str_html, ">") 'Go though the HTML Byte by byte cur_char = Mid(str_html, html_loop_1, 1) If cur_char = "<" Then 'Is it an openning carret? open_c = True close_c = False html_tag = ""'Clear the tag variable, For now. ElseIf cur_char = ">" Then 'Maby not... open_c = False close_c = True If InStr(html_tag, "<") Then html_tag = Right(html_tag, Len(html_tag) - InStr(html_tag, "<")) End If End If If open_c = True And close_c = False Then'If the carret is currently open... html_tag = html_tag & cur_char 'combine all the chrs after it until the carret closes... End If 'I am very sure there are tons of better ways to Do this, 'but this works fine. If close_c = True And open_c = False Then If Not cur_char = "<" And Not cur_char = ">" Then html_text = html_text & cur_char'Add Each char together aslong as its Not a carret (both kinds) or End If 'part of a tag. This part could use some work, its Not perfect and is rather buggy. End If ' 'So far this little project of mine only supports BOLD, ITALIC 'and UNDERLINE HTML tags. I may or may not add more support. 'I am lazy, so don't bet your dinner. ' If close_c = True And open_c = False Then html_tag = LCase(html_tag) 'Make sure the tag is lowercase. Select Case html_tag'Start going though the tag, and doing what it wants us To do Case Is = "b" pic.FontBold = True 'If the tag is on, make the text bold, Else dont... Case Is = "i" pic.FontItalic = True Case Is = "u" pic.FontUnderline = True Case Is = "/b" pic.FontBold = False Case Is = "/i" pic.FontItalic = False Case Is = "/u" pic.FontUnderline = False End Select pic.Print html_text; html_text = "" 'Clear the variables when we are done. html_tag = "" End If Next html_loop_1'And we are on our way... again. End Sub Name: Simple HTML Render Inputs:Picturebox, html code Returns: Rendered Html onto the picture box. A simple demo on how to write a HTML renderer. written by Dan Ushman <ushman@mediaone.net> Please visit Refsoft at www.refsoft.com |