Solved

Automatic Color Coding

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

911 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

19 Experts available now in Live!

Get 1:1 Help Now