|
-
Sep 23rd, 2000, 02:19 PM
#1
Thread Starter
Frenzied Member
If i have a rich text box that has text in it how can i make it run through each charachter at a time and colour it if it is a "<" when a button is clicked ????
-
Sep 23rd, 2000, 02:30 PM
#2
Hyperactive Member
Try this
Code:
Public Sub colorize()
Dim posEnd, posStart, x, i As Integer
x = 0
i = 0
For i = 0 To Len(RichTextBox1.Text)
RichTextBox1.SelStart = i
RichTextBox1.SelLength = 1
If RichTextBox1.SelText = ">" Then 'start tag
posStart = i
RichTextBox1.SelColor = vbRed
End If
Next i
End Sub
Have Fun
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Sep 23rd, 2000, 03:04 PM
#3
Thread Starter
Frenzied Member
Thankyou very much, nice code !!!!!!!!!!!!!!!!!
-
Sep 24th, 2000, 11:01 AM
#4
Thread Starter
Frenzied Member
Um, what if i want to colour all of the text but to different colours, i know how to do this except it misses some, is there anyway to slow the code down like a 10 millisecond pause before it does the next charachter ??
-
Sep 24th, 2000, 11:07 AM
#5
Hyperactive Member
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Sep 24th, 2000, 01:41 PM
#6
_______
<?>
Code:
'adding to the code supplied by PRIVATE1
'
Option Explicit
Public Sub Colorize()
Dim posEnd As Integer, posStart As Integer
Dim x As Integer, i As Integer, j As Integer
Dim myArr(5)
myArr(0) = vbRed
myArr(1) = vbBlue
myArr(2) = vbYellow
myArr(3) = vbMagenta
myArr(4) = vbGreen
myArr(5) = vbCyan
RichTextBox1.BackColor = vbBlack
x = 0 'start
i = 0 'start
Randomize
For i = 0 To Len(RichTextBox1.Text)
RichTextBox1.SelStart = i
RichTextBox1.SelLength = 1
posStart = i
j = Int(Rnd * 5) + 1
RichTextBox1.SelColor = myArr(j)
Next i
End Sub
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub Command1_Click()
Call Colorize
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 24th, 2000, 03:17 PM
#7
Thread Starter
Frenzied Member
What i want is like for the '=' to be coloured blue and the '"' to be coloured green except that when i do this because the for loop runs so quick it misses half the charachters, can i slow the loop down at the end just before the next so that it has to do that before it colours the next ??
-
Sep 24th, 2000, 04:04 PM
#8
_______
<?>
I don't have a problem with it missing any, the only
problem is it can't distinguish between " and "" or """"
it just takes all versions of " and colors them green.
Code:
For i = 0 To Len(RichTextBox1.Text)
RichTextBox1.SelStart = i
RichTextBox1.SelLength = 1
If RichTextBox1.SelText = "=" Then 'start tag
posStart = i
RichTextBox1.SelColor = vbBlue
End If
If RichTextBox1.SelText = """" Then
posStart = i
RichTextBox1.SelColor = vbGreen
End If
Next i
ps.Running a 650 k7 128Ram so speed is not a problem.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 25th, 2000, 02:27 PM
#9
Thread Starter
Frenzied Member
Your problem is that sellength = 1 so its only finding " whereas u need a seperate function where sellength = 2 and another where it is = 3 to findout i also needs to be incremented by 2 or 3 as well
-
Sep 25th, 2000, 02:46 PM
#10
Add the following to a Form with a RichTextBox
Code:
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
nStart = InStr(1, LCase(RichTextBox1.Text), sKeyword)
Do While nStart <> 0
If nStart > 1 Then
sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
Else
sPrevChar = " "
End If
If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
Else
sNextChar = " "
End If
With RichTextBox1
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = UCase(sKeyword)
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
End With
nStart = InStr(nStart + Len(sKeyword), LCase(RichTextBox1.Text), sKeyword)
Loop
End Sub
Private Sub Form_Resize()
RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
HighlightText ">", vbBlue
HighlightText "<", vbBlue
HighlightText """", vbRed
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|