?
Solved

Automatic Color Coding

Posted on 1998-08-03
4
Medium Priority
?
211 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 100 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 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