Make your own free website on Tripod.com

FoxPro Home Page FoxPro Windows95 How To Converting Creating ActiveX FoxPro Printing Guide FoxPro FTP Site

Tips, Tricks and Cool Code Snippets

Page Contents
Add a Field InputMask Property to your Data Dict. 3.0
Bad Field Name Error. All
Bring Back the SQL Thermometer Bar 2.6 3.0
Calculate Age in Years All
Capture lines from ASCII file All
Changing Push Button Prompts on the Fly 2.6
Create parameterized VIEWS VFP
Customize the string used for commenting in Visual 5.0
DDE: Communicating with Word Perfect FPW
Disable Timers during Debugging 3.0
Displays Estimated Time 'till Finish in a Loop. All
Hex to Decimal Conversion Example All
Invisible Buttons: Make them REALLY Invisible 2.6
Make Readonly SQL Cursor writeable All
Recovering a Lost Toolbar 3.0
Recycling Space From the Resource File 3.0
Return a Date for Specific Day of Week All
Return a Value from a Form 3.0
Runtime or Development? All
Use SQL to Display Duplicate Records All
WAV files, 2 Ways to Play Them FPW


Add a Field InputMask Property to your Data Dict.

VFP doesn't use the Comment property for fields (in the Table Designer). The Comment property is for any character string (up to 254 characters) you want to associate with the field. You can use the field Comment property to store the most significant thing that seems to have been left out of the data dictionary...the InputMask string. In the Form/Class Designers' Properties Sheet, enter this code in the InputMask property:

Peter Herzog, Ainring, Germany - 06/05/96


Bad Field Name Error

when you attempted to open a table? Usually, this error results from a mismatch between the table structure and the custom settings for the table stored in DBASEWIN.INI

(Custom settings are created when you choose the Table Records Window Properties from the Properties menu while a table is open.)

If the DBASEWIN.INI file is stored on your local machine, perhaps someone else on the network restructured the table so that it no longer matches the custom settings in your DBASEWIN.INI. Or maybe you restored an older version of the DBF without the corresponding INI file.

The Solution:

Simply open the table from the Command Window and display the records in BROWSE mode. Select Table Records Window Properties from the Properties menu and select the OK button. This will reset the properties so that your programs will work without this error popping up.

Michael Antonovich - 11/01/96


Bring Back the SQL Thermometer Bar

You can activate a dummy window to recover the thermometer bar during queries and still supress all other TALK messages from FoxPro.

Michael DeLoatch, August 95 FoxPro Advisor - 08/08/95


Calculate Age in Years

Calculate a person's age in years based on the current date.

Anonymous - 01/05/94


Capture lines from ASCII files

Capture lines from ASCII files which will result in text file (.TXT).

Gabin Max Pasquel Herrera - 08/10/96


Changing Push Button Prompts on the Fly

You can easily change the prompt of a push button by using SHOW GETS. This is useful when the event you wish to trigger from the button depends upon some condition. For instance, a push button might have the prompt "Modify" if child records existed but have the prompt "Add" if none had been entered yet.

Colin Keeler - 07/31/95


Create parameterizaed VIEWS

One of the coolest new features of VFP is the ability to create a VIEW. Not only do they allow us to create virtual tables based on Local or Remote data, but they can also be parameterized.

Parameterization allows us to slice the data any way we like it. One of the annoyances of parameterized views is that when they are opened, they expect all parameters to be defined. If they are not defined, VFP prompts us with a generic dialog where we can enter the parameter value.

I don't know about you, but this does not provide the polished application look and feel that I desire.

One obvious way to avoid the dialog is the make sure the parameter(s) are defined. But what if I don't know what slice of the data the user wants to look at? I could simply select some arbitrary value, however, this may result in pulling unnecessary data across the server. Maybe I don't want any data at all.

VFP allows us to handle any of these situations with the he addition of the NODATA clause. By using the NODATA clause in my USE statement for the view, I can instruct VFP to retrieve only the structure of the view, leaving unwanted data on the server were it belongs.

I can then issue the REQUERY function on the view I have enough information to define the parameter(s).

Brent Vollrath - 12/23/96


Customize the string used for commenting in Visual FoxPro

Visual FoxPro 5.0 supports commenting or uncommenting code with a right click or a menu selection. You can customize the string used for commenting (to include your initials, for instance) by adding one key to your registry.

HKEY_CURRENT_USER/SOFTWARE/MICROSOFT/VISUALFOXPRO/5.0/OPTIONS

Double click the new entry and type the string you want the commenting to use. Note that you'll have to provide the *entire* string, including the asterisk.

Dan Freeman - 01/14/96


DDE: Communicating with Word Perfect

The below snippet is an example of using DDE to perform communication between FPW and WPW. Two key things to remember about WPWin and DDE:

Another alternative would be to write a macro in WordPerfect and then have FPW start WPWin and execute the macro. The following line would do this:

Word for Windows is much easier to communicate with via DDE for two reasons:

Unknown - 06/16/94


Disable Timers during Debugging

Timers can be a useful tool in VFP interfaces but can become a real pain when debugging, especially when their interval is rather short. Imagine tracing through some code in the Trace window and being just about to figure out what's going on when...BOOM...a timer fires. Put this code in the Timer() event method snippet, and then to enable your timer thereafter, just enter _Screen.ActiveForm.MyTimer.Enabled=.T. in the Command window.

Steven Black, Kingston, Ontario, Canada - 06/05/96


Displays Estimated Time 'till Finish in a Loop.

Displays a message telling how many records have been processed, how many are to be done, and the estimated minutes till finish. Call within a loop such as a scan or do while. Store the start time before entering. Each time through the loop, call the function.

Garritt Grandberg - 07/15/96


Hex to Decimal Conversion Example

The following code demonstrates conversion from Hex to Decimal:

Colin Keeler - 03/01/94


Invisible Buttons: Make them REALLY Invisible

To make a Really Invisible Button, add the following code to the READ WHEN clause.

Colin Keeler - 01/05/94


Make Readonly SQL Cursor writeable

Luis Goco - FoxTalk - January 1994 - 08/10/95


Recovering a Lost Toolbar

Occasionally you may lose one of the toolbars. You know that it is not hidden behind something else, but you cannot find it. Maybe it is off the edge of the desktop (possibly due to changing your screen resolution). In any case, you cannot get it to reappear in your work area. What do you do? Reinstall FoxPro?

No, fortunately there is an easier solution. Simply open the resource file with the following commands:

Note the function SYS(2005). It insures that you open the current resource file. This is especially important if you have multiple resource files or work off the network. Next, locate the record that controls the size and position of the toolbar. The key to doing this is knowing that the resource file stores the type of record in a field named ID.

In this case, the record type used to identify toolbars has the text "TTOOLBAR" in the ID field. While there are several records with the ID "TTOOLBAR", each record has a unique NAME field. This field corresponds to the name of the toolbar as shown in the toolbar list. The types of toolbars include:

Next, you want to locate the Form Controls toolbar and delete it. Use the following commands.

Now pack the table and close Visual FoxPro and reopen it to activate the new resource file

(beware of case or use UPPER(NAME) = "FORM CONTROLS" to be safe.)

The next time you need the deleted toolbar, you will need to select it from the Toolbar options of the View menu. However, Visual FoxPro will open the toolbar in a default location that will be visible in your current screen resolution.

Michael Antonovich - 11/01/96


Recycling Space From the Resource File

What is the resource file? By default, Visual FoxPro (and prior versions of FoxPro) used a resource file named FOXUSER.DBF to store information between FoxPro sessions. For example, it would store the position and size of each window you opened. It also stored definitions for color sets and labels.

To be able to read from the file, you merely needed to be able to open it. As with any table, this only requires that no one have the table open exclusively. As more people began developing applications on a network, the problem of how to share the resource file when users were making changes and possibly using the same tables or even named windows. Certainly you did not want to have windows popping up on your screen in the same locations and sizes that Carol uses. So what did FoxPro do. They made the file READ-ONLY if the file was shareable. To be able to write to the resource file, you must have your own resource file that is READ-WRITE and non-shareable.

For the moment, lets assume that you have your own resource file either on the network or on your own workstation. You may have noticed that over time it has grown considerably in size. This is because FoxPro stores characteristics of almost every object you create in this file. Open a table in Browse mode and BAM! There goes another record into the resource file. Create a new form, report, and query and BAM! BAM! BAM! Three more records.

Of course, once a record exists for a Browse screen, form or query, the next time you open it, it will pop up in the same location and with the same location as the last time it was open. Often this is a good thing and you can even create applications that depend on this feature. However, most of the time, this information just takes up space. Of course, you could make your resource file READ-ONLY, but until you do or if you cannot, it collects information about everything you do.

How can you clean out this unnecessary information and recover some of that space without deleting important things that you need? First you need to open the resource file and browse its contents using the following commands:

Notice that field name ID identifies the records by type.

To delete all the records of a single type, you could enter the following command:

which will delete all the definitions for windows used with prior Browse commands (one for each table examined with Browse.

Michael Antonovich - 11/01/96


Return a Date for Specific Day of Week

Return a date which is a specific day of the week, where any_date is the initial date to calculate from and the_dow is the number of the day of the week you want to find (Sun=1, Mon=2, etc.).

Unknown - / /


Return a Value from a Form Them

"How do I return a value from a form?" It's really pretty simple. All you need to do is place:

in the UnLoad Event of the form. You need to keep a couple things in mind though.


Now that we've got the form built, we need to know how to call it. Call the form with:

where ABC is the form name and xyz is where the value will be stored. Tha value can be a memory variable or property.

TakeNote Computer Consulting - 01/13/97


Runtime or Development?

To check to see if a program is running under the runtime libraries or in the development version of FoxPro, use the following expression:

Colin Keeler - / /


Use SQL to Display Duplicate Records

To display potential duplicate records or keys, use the SQL statement below. This will result in a cursor containing each group which is duplicated, shown only once, along with the number of times that grouping exists in the table. If you don't want to know the number of times a duplicate appears, don't include the COUNT(*) as part of the SELECT.

Colin Keeler - 04/26/94


WAV files, 2 Ways to Play Them

Colin Keeler - 05/09/94



Return (200 max) newest entries from

Copyright ? 1996-97 Pro WEBDesign / Gustavo - webfox@cyberservices.com
All Rights Reserved

This Page was Launched on Thursday, December 5, 1996


FoxPro Home Page FoxPro Windows95 How To Converting Creating ActiveX FoxPro Printing Guide FoxPro FTP Site