5 Ways to Automate Development in FoxPro
I enjoyed putting together my last top seven list so much, that I decided to make another, more targeted list. This one, lists five ways that you can automate software development in Visual FoxPro. To clarify: this article is not about FoxPro automation! But rather, five tips on how you can get the development environment to work for you.
It surprises me how many FoxPro developers I know do not automate, even though the Fox team at Microsoft has given us a lot of tools to do so. As I mentioned in my last article, automation is one of the keys to better productivity. The more tasks you can do automatically, without thought and with little effort, the greater productivity you will enjoy! On top of that, by automation, we can eliminate a lot of thinking, planning, repetition, and needless toiling over the most mundane tasks.
Not every version of FoxPro features every item in my list (although, VFP9 gets them all). The point of this article is not to be exhaustive or to painstakingly document every feature’s introduction into the product; but rather, to get you thinking about automation to improve your production.
Without further ado:
1.) Use Macros
No, no. Not macro substitution! Macros from the Tools menu! FoxPro Macros are powerful little scripts that you can initiate with a mere key combination (like ALT+CTRL+A). You can write a macro to do almost anything. Their primary purpose in life is to automate keystrokes. For example, I have a whole set of macros that open various projects, sets system defaults, and closes/opens databases as necessary. A nice thing about FoxPro Macros is that it will record your keystrokes for you. To start, simply go to Tools / Macros; Click Record; enter the keystroke combination and macro name; and start typing in the command window. When done, click back on Tools / Macros and click OK to stop recording. Next time you want to run the sequence you just created, simply do the keystroke you defined!
Please note: chances are good that you’ll need to tweak the generated code, but don’t fret. In my experience, this consists of adding {ENTER} at the end of a command, or perhaps cleaning up some automatically-inserted values from IntelliSense. No big deal.
2.) Utilize and Customize IntelliSense
Speaking of IntelliSense! As most of you are aware, IntelliSense is a form of automated auto-completion of keywords, class names and methods, parameter definitions, _VFP and _SCREEN system variables, ActiveX controls, COM servers, and the like. But you can also add your own records in the IntelliSense database! You might want to define common enumerated values (like a long list of DEFINES you have tucked away in an include file), custom class definitions, and type libraries. You can also add IntelliSense support for registered type libraries, user-defined types, members, and code elements, enumerated values, and custom classes. IntelliSense is a powerful and easy to manipulate tool that can save you tremendous amounts of time during development.
There is already a great repository of custom IntelliSense scripts for you to browse through and incorporate into your FoxPro programs (hey, did you already forget how selfless the Fox community is?): find them over at the FoxPro Wiki. Andy Kramek also wrote (part 1, part 2) a very informative blog entry about the subject some time ago.
3.) Use Project Hooks
Project hooking allows you to manipulate your project and contained files programmatically. I find this incredibly helpful during builds (tapping into BeforeBuild and AfterBuild, for example), but there are dozens of great uses for hooking into your project. One of my favorite things to do is to log my project builds in a build table. This allows me to monitor and audit the build process (and produce some interesting metrics such as build time, number of builds, etc.).
If you’re at all interested in pursuing this any further, I highly recommend you look into White Light Computing, Inc’s Project Builder and ProjectHook. On that page, there is a very good Whitepaper detailing the tool (and a screenshot of the UI). Best part is, it’s free and developed by one of the community’s best.
The bottom line is that you can automate a ton of activities using these hooks. You can perform backups, make copies, test integrity, check for updates, copy builds to remote locations, etc. The limit is your imagination (for the most part!).
4.) Customize Your Toolbox
I love the Toolbox in VFP9 — especially because I’m used to developing in C#.Net and SSIS. The Toolbox (available form the Tools menu) to me is an intuitive piece of the IDE, and fits nicely into an automated work environment. It is divided into sections which you can customize. These sections are full of collections of various tools. These tools are typically classes, text scraps, Active X controls, and can even hold tables, images, reports, labels, and forms. You can drag and drop items from the toolbox into the command window, a program file, or onto a form. For automation, you can create lots of very cool text scraps (like comment headers) to save you some type and formatting time while developing.
To dig into the toolbox, and customize it fully, right click anywhere on the control and select ‘Customize Toolbox’. You can adjust various behaviors and add and remove items from the different categories. Note: to dock in VFP9, first set the ‘always on top’ property to false. Then, you can dock the toolbox anywhere your heart desires!
5.) Automated Testing
Although I have not had any success with commercial automated testing products (the last one I tried was Borland’s SilkTest, which did not work well with VFP9), I have had mild success using the Automated Test Harness that ships with VFP. The harness gives you the ability to create and run various scripts that will play back mouse and keyboard events — essentially running various parts of your application for you. I admit that even this tool isn’t the best, but you can automate enough tasks and perform enough tests automatically to save you time and effort on regression. The harness taps into Microsoft Active Accessibility (MSAA) technology. To run, type DO (HOME() + “tools\test\aatest”). It takes a bit getting used to, but in an afternoon, you can have the tool up and running, testing your application automatically. As an added bonus, the harness allows you turn coverage profiling on and off.
…
Well, that’s that! I hope you find these five ways to automate development in FoxPro useful. Assuredly, there are others. Feel free to comment and post articles, tips, or other feedback to round my list out!
I'm a Quant Technical Specialist (Data Warehousing and Business Intelligence), with expertise in business analysis, data modeling, and data integration. I have extensive experience developing vertical and integrated desktop, Internet, and BI applications spanning municipal, clinical, and financial industries.

July 30th, 2007 at 1:26 pm
Hi Tod,
Under IntelliSense, you mention adding custom IntelliSense records for common DEFINEs. Are you aware of the “zdef” IntelliSense script which ships with VFP? First, you have to make sure that you have the lAllowCustomDefScripts custom property set to .T. in the IntelliSense Manager. Then type “zdef” (without the quotes) followed by a space, and the script presents a list of all the DEFINEs for the current program or method, including those contained in INCLUDE files. The tooltip for each item displays the value of the constant. Very handy!
July 31st, 2007 at 8:28 am
Wow Mike! Great tip. Somehow I missed that in VFP8. Most of my projects went from VFP7 to VFP9 — so I admit to being a little fuzzy on the some of the cool things introduced in version 8. Some other cool little tidbits include (from VFP8’s new feature listing):
# Typing WS in a program (.prg) file opens the Select dialog box for choosing a registered XML Web service. XML Web services are no longer added in code using a type, for example, LOCAL oWS AS myWebService.
# Typing ZLOC in a .prg file displays a list of available local memory variables and parameters.
The complete lists IntelliSense scripts is located in FoxCode.dbf.
August 5th, 2007 at 4:01 pm
[…] DevelopmentURL Validator - RegExLibEmail Validator - RegExLib5 Ways to Automate Development in FoxPro - Tod McKennaArrays vs. Linked Lists - Adam […]
August 16th, 2007 at 1:56 pm
Hi Tod,
another speed-up for using macros: Put in your config.fpw:
MACKEY = Ctrl+F12
From now on, you just press Ctrl+F12 to directly launch the Macro-recorder. In earlier Foxpro-versions, that hotkey was Shift+F10, but then MS Windows assigned that one as the keyboardway for the Shortcut-Menues. That’s why we got SET MACKEY to assign our own hotkey.
Greetings from good ol’ Germany!
August 16th, 2007 at 10:04 pm
What a great tip!
September 6th, 2007 at 9:57 am
I’ve gotten some feedback about a member of the Chicago Foxpro User Group, Tom Corrigan, who is using Fox Trails as a code generator, instead of generating html. As I recall, he was using it to create C# classes.
September 6th, 2007 at 7:35 pm
That sounds pretty interesting. I can’t wait to see Brian’s presentation at Fox Forward. I’m in Atlanta now and gearing up!
March 16th, 2008 at 9:38 am
Tod,
if You remember CEE from the old old Fox2.6 days, have a look at my CEEClone for VFP7+, available at the UniversalThread. It is integrated into intellisense and gives You all the editor enhancements we had in earlier times and much more. Did it ages ago by now and could not live without it anymore.
Every time I do some .NET development, I go knuts and think I *must* do this for .NET as well