IntelliSense in VFP


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

IntelliSense provides a variety of services but I like the way 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/08/02

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 in my comments. 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 more now that it's easy.

How to do it

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.

[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.
  *-- There's a space after the tilde.
  *-- The expression in 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 putting DebugOut statements at crucial points.

Other uses

I've also modified the IntelliSense entries to help me write HTML. I'm writing this in VFP 7 now 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 CategoryIntelliSense.


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map