Solved

Automatic Color Coding

Posted on 1998-08-03
4
207 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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