Solved

Automatic Color Coding

Posted on 1998-08-03
4
196 Views
Last Modified: 2010-05-03
Currently I am developing a VBScript design environment. To do this properly I need a routine that will automatically read words like "SUB", "FUNCTION", ".LISTINDEX", ".ENABLED" etc. from a file or from the registry and color them approriately in a RichTextBox or something similar.
0
Comment
Question by:LordHorse
  • 2
4 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1467597
The following code will change the words in your example to red.  You can add new words using the same ElseIf code group as shown.  Each word can have a different color by changing that color in the code:

Private Sub RichTextBox1_Change()

  With RichTextBox1
    If UCase$(Right$(.Text, 3)) = "SUB" Then
      .SelStart = Len(.Text) - 3
      .SelLength = 3
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    If UCase$(Right$(.Text, 8)) = "FUNCTION" Then
      .SelStart = Len(.Text) - 8
      .SelLength = 8
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    If UCase$(Right$(.Text, 10)) = ".LISTINDEX" Then
      .SelStart = Len(.Text) - 10
      .SelLength = 10
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    If UCase$(Right$(.Text, 8)) = ".ENABLED" Then
      .SelStart = Len(.Text) - 8
      .SelLength = 8
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    End If
  End With
End Sub

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467598
Oops!  The code should read:

Private Sub RichTextBox1_Change()

  With RichTextBox1
    If UCase$(Right$(.Text, 3)) = "SUB" Then
      .SelStart = Len(.Text) - 3
      .SelLength = 3
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    ElseIf UCase$(Right$(.Text, 8)) = "FUNCTION" Then
      .SelStart = Len(.Text) - 8
      .SelLength = 8
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    ElseIf UCase$(Right$(.Text, 10)) = ".LISTINDEX" Then
      .SelStart = Len(.Text) - 10
      .SelLength = 10
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    ElseIf UCase$(Right$(.Text, 8)) = ".ENABLED" Then
      .SelStart = Len(.Text) - 8
      .SelLength = 8
      .SelColor = vbRed
      .SelStart = Len(.Text)
      .SelColor = vbBlack
    End If
  End With
End Sub

0
 

Author Comment

by:LordHorse
ID: 1467599
That code was cool, but it only changed text appended to the end of the RTBox and keeps moving the cursor to the end of the text. I need it to more or less look like the code window in VB.
0
 

Accepted Solution

by:
zabman earned 50 total points
ID: 1467600
LordHorse --

  I have a program that will do (hopefully) exactly what you want it to do,  I can't find the code right know to post it, but If you E-mail me at zabman@hotmail.com I can send you the compiled app.  If this is what you need and want, I will hunt down the code for you (It's on ONE of a MILLION DISKS):-o

  Hope to hear from you.

                                  -- Neil Z. :-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now