Hidden Secrets of the VFP IDE, Part 2
Cathy Pountney
FoxPro has always had several different ways to do the same thing. How many times have you looked over the shoulder of another developer and said, "Hey! How did you do that?" In this article Cathy Pountney uncovers many ways to work within the Ide, especially those there is ''. You'll Learn Several DIFFERENT WAYS TO IMPROVE YOURAL DIFFERENT WAYS TOEPROVE YOURAL DIFFERENT WAYS TOEPROVE YOURAL DIFFERENT WAYS TOEPROVE YOURAL DIFFERENT WAYS to Improve Your Productivity. Even Experienced Developers Are Bound To Learn Something New.
This is the second of two articles where I've been exposing several unknown secrets of the VFP IDE. In the first part, I discussed various designers, a few controls, the Property Sheet, the Document View, and the Find Dialog. Then I revealed some secrets of IntelliSense as well as several tools and utilities included with Visual FoxPro. In this article, I'll reveal secrets of the Command window, several commands, and wrap up with a potpourri of hidden secrets.
Command Window and Commands
THE COMMAND WINDOW IS ANOTHER Place We spend a Lot of Our Day. Here Area Tips That Can Be Used in The Command Window AS Well AS Some Lesser-KNown Secrets About Some of VFP'S Commands.
Command Window
Many people already know that you can highlight a line of code in the Command window, right-click, and choose Execute Selection to execute the highlighted code. But did you know that you can highlight multiple lines of code and execute them at once? However , you have to realize how this works or you might not get the expected results. When multiple lines of code are executed, a temporary program is created and then run. This means that variables can go out of scope after the chunk of code has been Run. This is really more of a "hidden gotcha" Than "Hidden Secret"! Another Thing You Can do in Command WINDOW IS Use THE Command WINDOW IS Use the Semicolon () As a Continuation Character Just As You Do In Code. This is Great When You're Copying Code from a Program OR WHEN You're Creating A Giant Select Statement That You Want To Be Able To Wrap.
_Cliptext
The first extra is a system variable called _CLIPTEXT. This contains the contents of the VFP clipboard. You can use it to set other information based on what's in the clipboard, and you can use it to define what's in the clipboard. It's a two- Way Variable That You Can Take Advantage Of At Design Time and Even At Runtime Wtem Application.
To demonstrate, highlight a line of code in the Command window and press Ctrl C to save it to the clipboard. Now enter? _CLIPTEXT in the Command window and you'll see that the line of code you highlighted is printed on the screen. Another Example Is To Run The Following Code to Create a Program:
_cliptext = '? "fox rocks"' chr (13) chr (10) ; '? "VFP 8 is Great" chr (13) chr (10) Erase Junk.PRG Modify Command Junk Nowait Keyboard' {Ctrl V} 'The Preceding Code Fills The Clipboard with Two Lines of Code, Creates a Program File, And The Pastes The Contents of The Clipboard Into The Newly Created Program.
_Vfp.DataToclip ()
The second extra that VFP has to help us with cut-and-paste functions is the _VFP.DataToClip () function. This function takes data from a table or cursor and puts it into the clipboard. From there, you can paste it anywhere else , including Microsoft Excel. The third parameter defines the format of the data. If you use a 1 in the third parameter, the data uses spaces to separate each field. However, if you use a 3 in the third column, tabs are used to Separate Each Field, Which Makes It Perfect for Inserting Into Excel Other Applications.
Printing the clipboard
Another little-known feature in VFP is the fact that you can print what's in the clipboard. This is great when you want to print a chunk of code from a program, but not the entire program. Highlight the text you want to print and select .. File | Print from the main VFP menu to invoke the Print dialog (you can also use Ctrl P to invoke the same dialog) from the Print dialog, select the Options button to display the Print Options dialog By default the Print What - Type Combo Box Is Filled In The Current Program. However, You CAN Select Clipboard, Select Ok, and The GO Back to The Print Dialog To Finish Selecting Your Printing Options.
Browse Keystrokes
WHEN Using The Browse Command, There Are Several Keystrokes You Can Use To Perform Special Operations, as Shown In Table 1.Table 1. Keystrokes with The Browse Command.
Keystroke What it does Ctrl F Find Next Ctrl G Find Previous Ctrl Y Add a record Ctrl T Toggle Deletion flag Ctrl Home Edit a memo field Ctrl W Save and close Ctrl F10 Toggle between maximize and restore
What's in a name?
The NAME clause can be very helpful for passing data around. The SCATTER, GATHER, and INSERT INTO commands all honor the NAME clause. This makes these commands much more powerful than in earlier days when you were used to SCATTERing into MEMVARs. Now that you CAN Scatter to a name, you can pass the data to another object as a parameter. The folload code shows an esample of how to do this:
* - Open Tables CLOSE TABLES ALL USE MyTable1 IN 0 USE MyTable2 IN 0 EXCLUSIVE ZAP IN MyTable2 * - Copy records from MyTable1 to MyTable2 SELECT MyTable1 GOTO TOP SCAN SCATTER NAME oMyTable AddToTableGather ( 'MyTable2', oMyTable) AddToTableInsert ( 'MyTable2' , omytable) Endscan Select MyTable2 Browse * - Close Tables Close Tables All Return *********************** ******** ***************** LPARAMETERS PCTABLE, POFIELDS LOCAL LCALIAS LCALIAS = alias () SELECT (PCTABLE) POFIELDS.DESCR = Alltrim (Pofields.Descr) 'g' Append Blank Gather Name Pofields SELECT (LCALIAS) RETURN ************************************************* ********* LPARAMETERS PCTABLE, POFIELDS POFIELDS.DESCR = Alltrim (Pofields.Descr) 'I' INSERT INTO (PCTABLE) from name Pofields Return
Another Great Example of Using The Name Clause Is With The Browse Command. In The Command Window, Enter the Following: Use MyTable1 Browse Name Obrowse
Now in the Command window, enter the string "oBrowse." (Do not forget the trailing period) and you'll see IntelliSense kick in as soon as you type the period. This is great-the browse window is now an object you Can Manipulate. Start Picking Some Properties, Such As Fontbold or RowHeight, from IntelliSense and You Can Manipulate The Browse Window Right from The Command WINDOW.
Implicit transform ()
In VFP 8, a few commands have implemented an implicit TRANSFORM () feature. This means that you can use data types that are not character, and the command will TRANSFORM it automatically for you. If the item being transformed is an object, the Text "(Object)" IS used.
Try The Following Commands and You'll Be Pleasantly Surprised That They Don't throw an error!
WAIT Window Date () MessageBox (500) DEBUGOUT DATE ()? _VFP
PotPourri
Here Are A Few More Hidden Secrets That Are Scattered THROUGHOUT VISUAL FOXPRO.
Shifty tricks
Using the Shift key before selecting a menu option can change the options on the menu. For example, pressing Shift and selecting the File menu changes the Close option to Close All. Using Shift along with the Window menu changes Hide to Hide All. Normally, .
Another feature that's been around for years and years in FoxPro and VFP is the Outshow feature. Pressing Ctrl Alt Shift hides all the windows except the one accepting output. They stay hidden as long as you continue pressing the key combination. As soon as you let go, all the hidden windows appear again. This is extremely useful when you display something from the Command window with the question mark (?) character and the results end up getting shown behind a bunch of other windows.Copy a class
At First, IT APPEARS THAT IRE ISN 'To, You Can Subclass It-But Thereesn't Seem To Be Any Way To Copy A Class. Well, With The Use of The Project Manager IT Can Be Acc.complased Quite Quickly with the Following Steps:
1. Drag The Source Class from One Library to Another.
2. Rename The Class in The New Library.
3. Drag the newly named class back to the Original Library.
4. DELETE The Class from The Temp Library.
Of Course, IT Would Be Nice IF The Right-Click Menu or Somewhere Else. But Heck, We can't Have Everything!
Drag and Drop
In VFP 8, the Project Manager was improved by allowing you to add multiple files at once. Prior to this version, you could only add one file at a time. However, you can use drag and drop to add multiple files, and this feature has been around for quite a while. Open the Project Manager and then open Explorer. Select some files in Explorer and drag them to the Project Manager. An added benefit is that the Project Manager is smart enough to figure out what tab to put each of The Different Files On Based on Their File Extensions.
_Vfp.setvar ()
This little-known function can be used to set variables in situations where you can not execute a command but you can call a function. A perfect example of when to use this is in the Report Designer. I use it all the time in the OnEntry and OnExit expressions of the various bands. For example, in the OnExit expression of a Group Footer, you can use _VFP.SetVar ( 'rnRecordCount', 0) to clear the value of the rnRecordCount variable. Or you can use _VFP.SetVar ('RNCOUNTDATAGROUPS', RNCOUNTDATAGROUPS 1) To increase a variable thing TRACks the number of data groups processd.wildcards
Some commands accept wildcards, and although this can be great to work with, it can also be dangerous. There's not much harm in entering MODI COMM MyProg *. All it's going to do is open up all the programs that are named starting with MyProg. However, Issue delete file myprog * .prg and "danger! Danger! Danger!" Flashs Across My Mind. Be Careful In How you use wildcards!
Just for fun
Whew! This has been an article full of information. By Now Your Brain Is Probably Getting Fuzzy, SO I'm Going to End with a few fun.
Filer
Years ago, Filer was what most FoxPro developers used to search and find files. After VFP 3.0, this disappeared and many developers screamed. Well, the Fox Team has listened and decided to bring back a little nostalgia. Enter the following in the Command window To See an Example of How IT Runs:
Do Form (HOME (1) Tools / Filer / Filer.scx ')
Search Through The VFP Help File and Read Up on The New Filer, Because THIS ONE IS Object-Oriented And You CAN Interact with IT And Implement It in Your Own Applications. I Guess You Cell Call this fileX!
Puzzle
Here's another long-lost feature of FoxPro that has been brought back in VFP 8. Enter the following in the Command window. However, be forewarned that this may severely reduce your productivity at work! ACTIVATE WINDOW PUZZLE
Error-Free Programs
Did You Know That Writing Error-Free Progras Is A Cinch with VFP? Just Enter The Following Line of Code In your Startup Program and You're all set.
ON Error *
Of Course, this Doesn't Mean That Your Program Is Bug Free. It Only Means That You Won't get any error message!
Love Your Work!
I know you love vfp so much this.
On shutdown *
No Matter How Hard You Try, You Can't Get Out of VFP Now. This is Great-You Can Sit in VFP 24/7 and Never Have To Leave! Okay, Okay, i Guess this isn't Such A Great Idea. I Guess You'd Better undo The Damage with the Following Code:
On Shutdown
Work Smarter, Not Harder
This pair of articles has been crammed full of information. My goal was to expose you to as many cool features as possible and to give you some "ah ha" moments. Some of it may not have been new to you, but for the parts That Were New, The Could Be huge-savers for you in the fulure. as i always say, "Work Smarter, Not Harder!"
To Find Out more about thisjournalname and Pinnacle Publishing, Visit Their Web Site At http://www.pinpub.com/
Note: this is not a Microsoft Corporation Web Site. Microsoft Is Not Responsible for ITS Content.