|
-
Jun 5th, 2000, 07:14 PM
#1
Thread Starter
Addicted Member
Hi, I'm trying to write a program that uses a richtextbox, and does what the VB Enviroment does to keywords, for example:
Code:
Public Sub SelectLineText(EditControl As Control, ByVal nLineNumber As Long)
Dim lIndex As Long
Dim lc As Long
Dim LineBuffer As String
'Ensure Linenumber valid
If nLineNumber < 0 Then nLineNumber = 0
lc = GetMaxLines(EditControl.hWnd)
If nLineNumber > lc - 1 Then nLineNumber = lc - 1
'Return starting char pos on passed line number
lIndex = SendMessageByNum(EditControl.hWnd, EM_LINEINDEX, nLineNumber, 0&)
'Return the length of the passed line number
lc = SendMessageByNum(EditControl.hWnd, EM_LINELENGTH, lIndex, 0&) + 1
EditControl.SelStart = lIndex
EditControl.SelLength = lc
Debug.Print EditControl.SelText
End Sub
See how this message board changes the colors of all the keywords and comments? I want my program to do the same, but it's proving a little harder than I thought it would be.
Has anyone already written a program like this, using a RichTextBox? Please let me knowwww. =)
-
Jun 5th, 2000, 07:15 PM
#2
Thread Starter
Addicted Member
Uh, what the heck?
Code:
'Testing
For x = 0 to 100
MsgBox("Why didn't it work???")
Next x
hmm...
-
Jun 6th, 2000, 07:59 AM
#3
Here's a code i used for a BASIC Editor, but it will work in your case as well. Make a Form with a RichTextBox in it. Add this code to the General Section.
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, 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
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)) Then
With RichTextBox1
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = UCase(sKeyword)
.SelStart = Len(RichTextBox1.Text)
.SelColor = vbBlack
End With
End If
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 "if", vbBlue
HighlightText "then", vbRed
HighlightText "else", vbMagenta
HighlightText "end", vbGreen
End Sub
This should get you started and you can add more words if you want as well.
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
|