Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Program Language Syntax Highlighting in VB5 and VB6

In order to get the code running under VB you will need the following controls (from VBAccelerator)

SSubTimer.DLL - great subclassing control/activex dll.

odcbolst.dll a great owner-drawn combo control.


This code highlights (a.k.a. colorizes) multiple languages depending on a syntax file specified by the programmer by parsing RTF instead of setting colors using .SelStart, etc so it looks good instead of ugly. It's also a lot faster.

A list of keywords/functions/subs/operators/etc. needs to be supplied in the syntax file (*.stx). Syntax files can be used w/ a simple text editor like Notepad. I (David Hoyt) am currently working on a Syntax File Editor that will be available in the future at http://vhtml.hypermart.net/ if you need it.

All information regarding functions/subs in the modDynHighlight.bas has been included in the module in the comments. The code is commented thoroughly. To implement the highlighting, call LoadSyntaxFile() and then Highlight().

It works by modifying the RTF code for a richtextbox, so appropriate code would be something like:

Call LoadSyntaxFile("C:\SomeFolder\vbsyntax.stx")
RichTextBox1.TextRTF = Highlight(RichTextBox1.TextRTF)

Syntax File Info.

Editing a syntax file requires a little knowledge for its format...it's divided into several sections:

Block - Sets how we know we're at the end of a block...in VB this would be nothing, but in c/c++ or java, it'd be a semi-colon (;)

Comments - This is a unique section...you can add different comment styles by using SingleLine= and MultiLineStart= and MutliLineEnd.

For C/C++ use this syntax:


Func Subs - This is a list of functions/subs for each programming language. This is not yet implemented in full so don't concern yourself too much w/ this.

Keywords - This holds a list of keywords for the programming language.

Operators - Sets operators such as =, !=, <>, >, <, +, -, *, etc.

String Delim - Sets how the language specifies a string. In VB it's a double quote (")

These categories must be enclosed by []s. Here's a small example syntax file:



[string Delim]


[Func Subs]


There ya go!! Just FYI -- you can include comments by specifying the first character of a line as a semi-colon. For example:

;The keywords section...
;This is a comment!!
ActualKeyword ;uh-oh this will give you an error!! _
              Can't have a comment on the side!

Blank spaces are also ignored. So maybe you're wondering how you would include a semi-colon if it was needed for a block statement perhaps? That's simple!! Just put a space in front of it and it will be read like normal in the code. Except in certain cases, each item added is stripped of trailing and beginning spaces (uses Trim() function). Once again, I am working on a syntax file editor that I'll try to finish up ASAP. Look for it on the URL I specified above. Once that is done, you won't have to worry about following all that funky syntax for my syntax files!! (c; Well, hope you like the code!!

Click here for a larger image.

Download zipped project file (126k)


  • Project Guide - 2000 with new Master Wizard technology

    Posted by Legacy on 10/19/2000 07:00am

    Originally posted by: Boris Vigodny

    About color highlighting there is another way to do this.
    You can see my URL: http://pguide2000.narod.ru/index.htm
    I use logical blocks for color Analyzes and get some usefull effects respectively.

    Vigodny Boris

  • Using RichTextBox 32

    Posted by Legacy on 03/12/2000 08:00am

    Originally posted by: Nick Palmius

    I need to use this code with a RichTextBox 32 but this dosn't seem to work, also note that if you change the "UseVersion" Property on the vbalRichEdit Control that came with the sample to "0-eRICHED32" it dosn't work either,
    anyway any help would be helpful

  • HTML Article is at ....

    Posted by Legacy on 05/02/1999 07:00am

    Originally posted by: Chris Eastwood


    Sorry it took so long to add it.

    Chris Eastwood

    CodeGuru - the website for developers

  • I'll be adding the HTML Highlighting Article Soon !

    Posted by Legacy on 04/06/1999 07:00am

    Originally posted by: Chris Eastwood

    For those who want it, David's send me the code for the HTML highlighting and I'll be adding a new article here in the next few days.

  • HTML Syntax Highlighting

    Posted by Legacy on 04/04/1999 08:00am

    Originally posted by: David Hoyt

    This is in response to the previous post about HTML and ASP syntax highlighting. I have not created an ASP syntax file simply b/c I don't know much about it at all. I would need someone else to develop this. It would be MUCH appreciated if anyone would do this! If you so desire, you can provide me w/ the syntax rules, keyword list, and functions/subs for it and I'd be happy to create a syntax file for it. The code for the program language syntax highlighting does not color on the fly simply b/c I haven't had time to develop that portion yet. But there's already support for syntax highlighting like VB does it (colors a line after you leave it...just look at VB if you don't know what I'm talking about). If someone develops this first and sends it to me, I'd gladly give them credit. (c; As for HTML...I have already created HTML syntax highlighting. I created this separate b/c it follows certain rules that I could utilize to make the code highlight faster. So it has its own special routine. Perhaps I will post an article on it if enough people ask for it. Otherwise ask me and I'll send you my syntax highlighting control (comes w/ the source so you can modify it...it requires no external syntax files like this code). It colors tags, attributes, comments, and text. With what I've seen in other VB HTML syntax highlighting routines, you've always had to use quotes ("") for it to color properly. Not w/ mine...it works fine w/o quotes. If you would like this control, please contact me at the e-mail address listed. Thank you! (c;

    -David Hoyt

  • Program Language Syntax Highlighting in VB5 and VB6

    Posted by Legacy on 04/03/1999 08:00am

    Originally posted by: David Miles

    Great Article would be nice to see some syntax files for ASP and HTML

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date