Solved

Automatic Color Coding

Posted on 1998-08-03
4
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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