|
-
Mar 26th, 2005, 08:55 AM
#1
Need-a-life Member
Re: Color coding
 Originally Posted by Tempestknight
Sure
VB Code:
Option Explicit
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
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
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With RichTextBox1
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = sKeyword
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
End With
End If
nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Loop
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
HighlightText "END", vbRed
HighlightText "GOTO", vbYellow
HighlightText "IF", vbBlue
End Sub
thats what i got i want it to go back to black after i type say GOTO or IF or END...
It does a little flicker... but can't think of another solution without messing around too much with the code.
VB Code:
Option Explicit
Private Sub UnHighlightText(iColour As Long)
Dim iPos As Long
With RichTextBox1
iPos = .SelStart
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = iColour
.SelStart = iPos - 1
End With
End Sub
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
Dim iPos As Long
nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
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
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With RichTextBox1
iPos = .SelStart
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = sKeyword
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
.SelStart = iPos
End With
End If
nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Loop
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
UnHighlightText vbBlack
HighlightText "END", vbRed
HighlightText "GOTO", vbYellow
HighlightText "IF", vbBlue
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 26th, 2005, 09:01 AM
#2
Thread Starter
Addicted Member
Re: Color coding
if u test that u will see it ****s up
The Tempest Shall Never Die.
-
Mar 26th, 2005, 09:02 AM
#3
Thread Starter
Addicted Member
Re: Color coding
ok that still doesn't do what i want it to... it just keeps going same color like last time
The Tempest Shall Never Die.
-
Mar 26th, 2005, 09:05 AM
#4
Need-a-life Member
Re: Color coding
 Originally Posted by Tempestknight
ok that still doesn't do what i want it to... it just keeps going same color like last time
I don't understand what you need then. Can you posted the sample text you want COLORED, please??
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 26th, 2005, 09:09 AM
#5
Thread Starter
Addicted Member
Re: Color coding
ok lol... say if i have
IF T23, @hast23
ok i want that whole line blue but then if i i have
IF T23, @hast23
1: hey
i want IF T23, @hast23 to be blue and the 1: hey to be black
The Tempest Shall Never Die.
-
Mar 26th, 2005, 09:21 AM
#6
Need-a-life Member
Re: Color coding
So you want this:
IF T23, @hast23
1: hey
I think I deserve a couple of votes for all this help 
VB Code:
Option Explicit
Private Sub UnHighlightText(iColour As Long)
Dim iPos As Long
With RichTextBox1
iPos = .SelStart
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = iColour
If iPos - 1 >= 0 Then
.SelStart = iPos - 1
End If
End With
End Sub
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
Dim iPos As Long
Dim sLine As String
nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
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
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With RichTextBox1
iPos = .SelStart
.SelStart = nStart - 1
sLine = Mid$(.Text, .SelStart + 1)
If InStr(sLine, vbCr) Then
sLine = Left$(sLine, InStr(sLine, vbCr) - 1)
End If
.SelLength = Len(sLine)
.SelColor = iColour
' .SelText = sKeyword
' .SelStart = Len(RichTextBox1.Text)
' .SelColor = iColour
.SelStart = iPos
End With
End If
nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Loop
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
UnHighlightText vbBlack
HighlightText "END", vbRed
HighlightText "GOTO", vbYellow
HighlightText "IF", vbBlue
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 26th, 2005, 09:37 AM
#7
Thread Starter
Addicted Member
Re: Color coding
OK lol that all works thank you. but now when u go and say u have
END
and u wanna change it to
END SCENE
u have it and u try to edit it but it brings you to next line. like u have
END
and add scene to it youll end up with
END S
CENE
because it brings you to next line know why? lol and yes i will vote for you :P lol i already gave u one yesterday
The Tempest Shall Never Die.
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
|