Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / VBScript
Article

Syntax Colouring for VBScript in Visual Studio 6

Rate me:
Please Sign up or sign in to vote.
3.60/5 (7 votes)
31 Dec 2001CPOL2 min read 64K   19   2
A simple registry modification to make Visual Studio apply syntax colouring to VBScript files.

Introduction

Visual C++ does not provide nice features such as syntax colouring for many languages other than C++ itself. One of these "poorer relation" languages is VBScript. With the increasing availability and usefulness of VBScript since the original release of Visual Studio 6, it may be quite desirable to use VBScript for purposes such as creating build scripts. However, it can be quite difficult to read yet another programming language without syntax colouring to lend a helping hand. As a result, it may be quite discouraging to new users to dabble with VBScript as part of a Visual C++ project.

There is a simple solution for this problem!

Modifying the Registry

Although Visual Studio doesn't provide syntax colouring for .vbs files, it does provide syntax colouring for its own VBScript macro files, which have the extension .dsm. It turns out that adding VBScript syntax colouring for another type of file is as simple as adding the file's extension to a list in the registry.

First of all, close Visual Studio before starting, as it will subsequently repair any registry modifications that you make while it is open. Then open a registry editor such as Regedit and find the registry key HKCU\Software\Microsoft\DevStudio\6.0\Text Editor\Tabs/Language Settings\VBS Macro. It contains a REG_SZ (string) value called FileExtensions. This value will already contain "DSM"; if you modify it to read "DSM;VBS" then restart Visual Studio, VBScript files with the extension .vbs will now benefit from the same syntax colouring as Visual Studio macro files.

Limitations

This registry modification adds no new functionality to Visual Studio, so the syntax colouring will suffer from any limitations already found when using .dsm files. This includes incomplete colouring of some well-established syntax (for example, Boolean operators such as And and Or are not coloured), and of course the syntax colouring will not recognise more recent additions to Windows Scripting. Using this functionality to colour XML-based Windows Script Files (.wsf) will only be a partial success! However, the syntax colouring available through this method does add considerably to the readability of VBScript code despite these limitations.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
Gavin Greig has been a developer with Insights Learning & Development Ltd. in Dundee, Scotland since 1996, using Visual C++ and the MFC.

He is a graduate of St. Andrews University, where he studied Physics and Electronics, and has a Computer Science M.Sc. and a Ph.D. from Dundee University.

He has also worked as a MUMPS developer in the British National Health Service, and recommends that you have a look at MUMPS yourself to see a perfect example of how programming languages should not be done.

Comments and Discussions

 
GeneralBest one yet Pin
Ergin Salih30-Sep-02 17:20
Ergin Salih30-Sep-02 17:20 
GeneralNice One Gavin! Pin
Davy Mitchell3-Jan-02 4:23
Davy Mitchell3-Jan-02 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.