Library code snippets
Colour HTML Tags (2)
This is another example of how to colour HTML tags. Add a RichTextBox to your form, and a command button called cmdColour. Then use the following code
Private Sub ColorHTML(RTF As RichTextBox)
Dim sHTML As String
Dim nTagOpen As Long
Dim nTagClose As Long
Dim nI As Long
Dim nColor As Long
sHTML = RTF.Text
nTagClose = 1
With RTF
For nI = 1 To Len(sHTML)
' *** See where the next tag
starts.
nTagOpen = InStr(nTagClose,
sHTML, "<")
If nTagOpen = 0 Then Exit For
If LCase(Mid(sHTML, nTagOpen,
4)) = "<img" Then
nColor =
&H400040
ElseIf LCase(Mid(sHTML,
nTagOpen, 2)) = "<a" Then
nColor =
&H8080&
ElseIf LCase(Mid(sHTML,
nTagOpen, 2)) = "<b" Then
nColor =
&H8000000F
Else
nColor =
&H4000&
End If
' *** See where the tag ends.
nTagClose = InStr(nTagOpen,
sHTML, ">")
If nTagOpen = 0 Then nTagClose
= Len(sHTML)
If nTagClose = 0 Then nTagClose
= Len(sHTML)
' *** Color the tag.
.SelStart = nTagOpen - 1
.SelLength = nTagClose -
nTagOpen + 1
.SelColor = nColor
Next
End With
End Sub
Private Sub cmdColour_Click()
ColorHTML RichTextBox1
End Sub
Related articles
Related discussion
-
Regarding Visual Basic Programme
by manjunathsl2007 (0 replies)
-
how do you hide all in VB6
by CapnJack (1 replies)
-
Problem with Input File
by novavb6 (3 replies)
-
How to produce a txt file with a table??
by novavb6 (1 replies)
-
VB6 compatability from XP to Vista
by bronx (1 replies)
This thread is for discussions of Colour HTML Tags (2).