Saturday, April 16, 2005

Paying It Forward VFP Tips - IntelliSense

Earlier today a fellow FoxPro developer sent me a question about an IntelliSense script Andy Kramek wrote about in MegaFox. Normally I pass along the questions I get on topics I did not write about to the original author, but in this case I had an alternative solution to pass along.

Our reader asked for some help with the InLineGetLocVars script found on page 74. So I looked up the section in MegaFox and re-read the tip. This cool script is designed to drop down a list of declared variables when you type in the first two letters of a memory variable following the standard of a scope letter and data type letter. This is a common code standard adopted by VFP developers. Local character variables start with “lc”, local date variables with “ld”, character parameters start with a “tc”, and so on. Once you type in the second letter and hit the spacebar, a dropdown list appears with all the variables declared in the procedure or method. This is a very power and very productive IntelliSense script.

Reading this section reminded me of a moment a few months ago when I was sitting in Cleveland listening to Andy speak on IntelliSense. Andy demonstrated a script that ships with VFP 8 and 9 that I had never seen. In one of your programs type in the following:

zloc

And press the spacebar. Bingo, all the local variables and any parameters for this procedure are in a dropdown list. You can type zloc anywhere in the code line. There are two advantages of this script compared to the one Andy created for MegaFox. The first advantage is you do not need to know what the variable starts with. The second advantage might not be a practical advantage for many developers, but your variables do not have to conform to the industry variable naming standard. At first this might sound like a bad idea, but I often work with code written by other developers who do not code to the same standards I have established.

Both IntelliSense scripts (the MegaFox example and the native VFP) require you to have your variable declared (which is something everyone should be doing by default anyway – another part of my development standards and best practices I subscribe to in an attempt to retain sanity).

There are a couple of gotchas you have to watch for with this IntelliSense script. The variables in this list are only the variables declared between the beginning of the method/procedure and where your type in zloc. The other gotcha is PRIVATE memory variables are not included (note it is called zLOC).

Now something I did not share with our reader is the cousin script to the zloc script, the zdef script. The zdef script will drop down all the constants you have declared in #DEFINEs. Both of these scripts provide a dramatic increase in productivity and I hope it adds to yours.

The person who sent me the question was slightly embarassed they did not know about the zloc script. I perfer to look at it from a different perspective. One can never know everything about FoxPro, it is impossible. I love the fact I have the opportunity to learn something new about my profession and the tools I use in my profession every single day.

So why did I title this blog entry “Paying It Forward VFP Tips?” It is simple: I don’t want to be the last person to learn the tip so I try to tell others. If every developer passes along this tip to a couple other FoxPro developers, and they pass it along to another couple of developers, and so on, this tip will make the rounds in no time. Pay it forward!

2 Comments:

At 4/21/2005 12:14:00 AM, Anonymous Andy Kramek said...

Of course, you could just use BOTH scripts. Modifying the test for specific variable prefixes in my script so that if what the user typed is not found the UserTyped property on the passed in FoxCode object is replaced with "zloc" as follows:
IF NOT INLIST( lcKey , "lc", "ln", "ll", "lo", "lu", "ld", "lt", ;
"tc", "tn", "tl", "to", "tu", "td", "tt" )
loFoxCode.UserTyped = "zloc"
RETURN .F.
ENDIF

Now you have the best of both worlds. The ability to filter variables by the prefix, but if there is nothing found with the prefix you automatically get the list of all declared variables afterwards....

 
At 4/21/2005 12:46:00 AM, Blogger Rick Schummer said...

Nice addition Andy! I am looking forward to watching your FoxCast when it becomes available. Unfortunately I will not be able to attend the live version, but that is the beauty of FoxCast. Developers can watch it when ever they have the time. Your IntelliSense session is one of those sessions you can listen to several times and learn something new each time.

 

Post a Comment

<< Home