IntelliSense in Visual FoxPro

IntelliSense was advertised as something that would bring VFP up to the level of Visual Basic but in typical FoxPro fashion the team went one better.

IntelliSense provides a variety of services but I particularly like the way that we can add our own entries to the FoxCode table. As an example, if I type CB in a program now I get:

*-- |
*-- Changed by Geoff Franklin - 23/06/09

where the date is inserted automatically and the cursor is positioned one space to the right of the '*--' on the first line, ready for me to type my comments into the program. It's a big help when I'm editing other people's code. I've always known that I ought to be commenting my changes and I do it a lot more now that it's so easy.

How to use VFP Intellisense

You can hack the FoxCode table directly but it's easier to start by using the IntelliSense Manager. This is available on the Tools menu or by typing DO FoxCode in the Command Window.

[VFP IntelliSense Manager]

  • Select the Custom tab and type a new abbreviation - in this example I've used CB for 'Changed By'.
  • Click the Script button and what looks like a procedure-editing window will open.
  • Write this code in the window:

LPARAMETER oFoxCode
LOCAL lcDate          && System date as a string.
LOCAL lcComment       && The text to be inserted.

lcDate = DTOC(DATE())

IF oFoxCode.Location = 1
  *-- We're editing a program so make the substitution.
  *-- The tilde marks where the insertion point will be.
  *-- Note that there's a space after the tilde.
  *-- The expression inside the <<double chevrons>>
  *-- will be evaluated.
  oFoxcode.valuetype = 'V'
  TEXT TO lcComment TEXTMERGE NOSHOW
   *-- ~
   *-- Geoff Franklin - <<lcDate>>
  ENDTEXT
ELSE
   *-- We're not editing so return the keystrokes unchanged
  lcComment = oFoxCode.Abbrev
ENDIF

RETURN lcComment
  • Save your changes by closing the edit window and the IntelliSense Manager.
  • Open a program edit window and test the new entry by typing CB. You should see the 'CB' disappear and be replaced by the comments.
  • If it does not work, open the IntelliSense Manager and make sure that Enable IntelliSense is ticked on the General tab.
  • Debugging a script is difficult. You can insert Set Step On into the code to open the debug window and suspend execution but you cannot Resume again. The best way of debugging is to go back to the old technique of adding DebugOut statements at crucial points.

Note that this piece of code used FoxPro's text merge commands.

Other uses

I've also modified the IntelliSense table entries to help me write HTML. I'm writing this page now in VFP 7 and I've just inserted a pair of paragraph tags:

<p>
   |
</p>

by typing the two-character code PP. This inserts the tags then moves up a line and two spaces across so that my text will be nicely formatted.

Further information

There's some help in VFP Help under 'IntelliSense' and 'Scripting' and you can look at the sample entries on the IntelliSense Manager. There are more good examples on the VFP Wiki under the CategoryIntelliSense heading.