Hidden Secrets of the VFP IDE, Part 2

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 that aren't so obvious or aren't documented. You'll learn several 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 are some 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 a "hidden secret"!

Another thing you can do in 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 within your 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 then 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 or 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 with the current program. However, you can select Clipboard, select OK, and then 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 following code shows an example 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 ************************* FUNCTION AddToTableGather ************************* LPARAMETERS pcTable, poFields LOCAL lcAlias lcAlias = ALIAS() SELECT (pcTable) poFields.Descr = ALLTRIM(poFields.Descr) + 'G' APPEND BLANK GATHER NAME poFields SELECT (lcAlias) RETURN ************************* FUNCTION AddToTableInsert ************************* 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." (don't 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 aren't 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, the Format | Font option changes the font in the Command window. However, using the Shift key with the Format menu changes the Font option to Screen Font, which changes the font of the VFP screen.

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 there isn't a way to copy an existing class in VFP. You can subclass it–but there doesn't seem to be any way to copy a class. Well, with the use of the Project Manager it can be accomplished 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 there was a copy button on 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't 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 that tracks the number of data groups processed.

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!" flashes 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 things.

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 could call this FilerX!

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 programs 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 messages!

Love your work!

I know you love VFP so much that you never want to leave it. Well, no problem. When you start up VFP, enter the following line of code:

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, they could be huge time-savers for you in the future. 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.

This article is reproduced from the March 2004 issue of thisjournalname. Copyright 2004, by Pinnacle Publishing, Inc., unless otherwise noted. All rights are reserved. thisjournalname is an independently produced publication of Pinnacle Publishing, Inc. No part of this article may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent of Pinnacle Publishing, Inc. To contact Pinnacle Publishing, Inc., please call 1-800-788-1900.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值