|
-
Aug 22nd, 2000, 04:57 AM
#1
Thread Starter
Addicted Member
Hi,
How do I highlight code like VB in a Rich Text Box in the same way that this forum does (with ) and like it does in their developers code book. Is there a reference or component I can use or would I have to check the text myself through code and highlight it that way?
Thanks
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Aug 22nd, 2000, 05:31 AM
#2
Fanatic Member
Not sure if this is what you mean, but try it anyway:
Code:
Private Sub Command1_Click()
With RichTextBox1
.SelStart = 10 ' Put any number you want here
.SelLength = 14' and here
.SetFocus
End With
End Sub
-
Aug 22nd, 2000, 05:37 AM
#3
Thread Starter
Addicted Member
Hi coox,
Sorry, that isnt what I mean. What I am trying to do is to have an example of vb code in a RTB and then highight it like it does in VB. ie. Private Sub is in blue, Comments are in Green etc... I could check through the text myself changing the colours of certain words but I was wondering if there was some sort of component that would do this for me.
Cheers anyway
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Aug 22nd, 2000, 07:49 AM
#4
Fanatic Member
Hmmm, dunno - the guys here at VB-World have figured something out, coz when you put "[code]" in your post the result get's nicely coloured. Really don't know though...
-
Aug 22nd, 2000, 07:54 AM
#5
Is this what you mean? Add a RichTextBox and insert the following code into it.
Code:
Option Explicit
Const vbDarkBlue = &H800000
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer
Dim sPrevChar As String
Dim 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 = StrConv(sKeyword, vbProperCase)
.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", vbDarkBlue
HighlightText "then", vbDarkBlue
HighlightText "else", vbDarkBlue
HighlightText "for", vbDarkBlue
HighlightText "next", vbDarkBlue
HighlightText "do", vbDarkBlue
HighlightText "while", vbDarkBlue
HighlightText "until", vbDarkBlue
HighlightText "loop", vbDarkBlue
End Sub
-
Aug 22nd, 2000, 07:55 AM
#6
Fanatic Member
[/code]
I'm pretty sure they use an ActiveX DLL. Just ask John (after he's finished with Mrs. Le Pont) for it in Forum Feedback,
-
Aug 22nd, 2000, 07:57 AM
#7
Thread Starter
Addicted Member
Hi Megatron,
Yes, that is what I am looking for only without the need to type in all the names of keywords etc.. Is there a reference or component I can use or will I have to check for them all manually (like the above code does).
Cheers Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Aug 22nd, 2000, 08:39 AM
#8
Hyperactive Member
On http://www.codeguru.com/vb are some nice working examples of syntax colouring for various languages incl. VB
-
Aug 22nd, 2000, 08:44 AM
#9
Thread Starter
Addicted Member
Cheers Crazy D, that was exactly what I was looking for 
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Aug 22nd, 2000, 10:39 AM
#10
You can also use the CreateWindowEx API to create an instance of the class VbaWindow.
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
|