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:
=DBGETPROP("Customer.CustNo","FIELD","COMMENT")
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.
DEFINE WINDOW dummy FROM 0,0 TO 1,1 SET TALK WINDOW dummy SET TALK ON * * put your query here * SET TALK OFF RELEASE WINDOW dummy
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.
age=YEAR(DATE())-YEAR(dob) IF CTOD(LEFT(DTOC(DATE()),6)+"00")<CTOD(LEFT(DTOC(dob),6)+"00") age=age-1 ENDIF
Anonymous - 01/05/94
Capture lines from ASCII files
Capture lines from ASCII files which will result in text file (.TXT).
Syntax:
SET PROCEDURE TO cap_line
DO cap_line WITH 'file.xxx',line_beg,line_end
*:************************************************************* *: *: Procedure file: CAP_LINE.PRG *: *: System: Capturar l¡neas de un archivo .TXT *: Author: Gabin Max Pasquel Herrera *: Copyright (c) 1996, ** Todos los derechos reservados ** *: Last modified: 05/03/96 14:20 *: *: Procs & Fncts: CAP_LINE() *: Call : VER_REPO() *: *: Documented 08/10/96 at 12:25 FoxDoc version 2.10f *:************************************************************* function cap_line parameters que_file,line_ini,line_fin if type('que_file') # 'C' .or. type('line_ini') # 'N' .or. type('line_fin') # 'N' wait window [=CAP_LINE(archivo,linea1,linea2)] wait window [Formato erroneo...] timeout 10 return space(0) endif tam_memo=set('memowidth') &&Almaceno el tama¤o del memo actual set memowidth to 255 file_full =fopen(que_file) && Abro mi archivo de toma file_size =fseek(file_full,0,2) && Calculo el tama¤o de este archivo filebakup =sys(3) && Temporal de almacenamiento de las l¡neas a capturar file_bakup =fcreate(filebakup+'.txt',0)&& Creo el temporal if empty(file_size) =fclose(file_full) && Cierro el archivo =fclose(file_bakup) && Cierro el archivo erase (que_file) erase &filebakup..txt return space(0) endif =fseek(file_full,0) && Me muevo a la primera posici¢n *Me ubico en la l¡nea que se desea for avanz= 0 to iif(line_ini=1,0,(line_ini-1)) =fgets(file_full) endfor if empty(line_fin) *Capturo el resto del archivo do while !feof(file_full) &&Realizar mientras no sea fin de texto =fputs(file_bakup, fgets(file_full)) enddo else *Capturo el resto del archivo hasta la linea limitante for conti= line_ini to line_fin &&Realizar mientras no sea fin de texto =fputs(file_bakup, fgets(file_full)) endfor endif =fclose(file_full) && Cierro el archivo =fclose(file_bakup) && Cierro el archivo return filebakup * EOF: CAP_LINE
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.
IF [condition] SHOW GET buttonname,1 PROMPT "Add" ELSE SHOW GET buttonname,1 PROMPT "Modify" ENDIF
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.
"Please enter the value for I_cParmVal:"
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.
USE myview NODATA
I can then issue the REQUERY function on the view I have enough information to define the parameter(s).
Local I_cParmVal I_cParmVal = "MEI" = ReQuery("myview")
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.
Run REGEDIT. Open the following key:HKEY_CURRENT_USER/SOFTWARE/MICROSOFT/VISUALFOXPRO/5.0/OPTIONS
From the Edit menu, select New/String Value. Name the value EditorCommentString.
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.
Here's how mine looks: *! djf !*-- m.g_devauthor = PADR( c_hdr_author_LOC ,45," ") *! djf !*-- m.g_devcompany = PADR( c_hdr_company_LOC ,45," ") *! djf !*-- m.g_devaddress = PADR( c_hdr_address_LOC ,45," ") *! djf !*-- m.g_devcity = PADR( c_hdr_city_LOC ,45," ")
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:
! /N1 c:\wpwin\wpwin.exe /fl /m=macroname
Word for Windows is much easier to communicate with via DDE for two reasons:
= DDESetOption('SAFETY',.F.) m.ChanNum = DDEInitiate('WordPerfect','Commands') IF m.ChanNum = -11 /N1 c:\wpwin\wpwin.exe /fl m.ChanNum = DDEInitiate('WordPerfect','Commands') ELSE =DDEExecute(m.ChanNum,"FileNew()") ENDIF =DDEExecute(m.ChanNum,"FontBold(On!)") =DDEExecute(m.ChanNum,"TYPE(Desk)") =DDEExecute(m.ChanNum,"FontBold(Off!)") =DDEExecute(m.ChanNum,"FontItalic(On!)") =DDEExecute(m.ChanNum,"TYPE({Desk})") =DDEExecute(m.ChanNum,"FontItalic(Off!)") =DDEExecute(m.ChanNum,"TYPE( Used to keep your papers off the floor)") =DDEExecute(m.ChanNum,"HardReturn()") =DDEExecute(m.ChanNum,"FontBold(On!)") =DDEExecute(m.ChanNum,"TYPE(Chair)") =DDEExecute(m.ChanNum,"FontBold(Off!)") =DDEExecute(m.ChanNum,"FontItalic(On!)") =DDEExecute(m.ChanNum,"TYPE({Chair})") =DDEExecute(m.ChanNum,"FontItalic(Off!)") =DDEExecute(m.ChanNum,"TYPE( Used to keep your butt off the floor)") =DDEExecute(m.ChanNum,"FileSave(Filename:'c:\docs\doc.wp'; ExportType:WordPerfe ct51!;Overwrite:Yes!)")
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.
IF WVISIBLE("Trace") THIS.Enabled=.F. ENDIF
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.
* * Procedure: fEstFin * Programmer: Garritt Grandberg * Date: 7-15-96 * * Parameters: * nStart,nCurRec,nTotRecs * * Variables: * nStart - Holds the start time, obtained using the SECONDS() function * nCurRec - Holds the current record # * nTotRecs - Holds totals records to be done * * Modifications: Date Init. Purpose * FUNCTION fEstFin PARAMETERS nStart,nCurRec,nTotRecs PRIVATE nStart,nCurRec,nTotRecs WAIT 'Processing '+ALLTRIM(STR(nCurRec))+' of '+ALLTRIM(STR(nTotRecs))+CHR(13)+ ; ' Minutes Left: '+; ALLTRIM(STR((((SECONDS()-nStart)/nCurRec)/60)*(nTotRecs-nCurRec),6,1)) ; WINDOW NOWAIT RETURN
Garritt Grandberg - 07/15/96
Hex to Decimal Conversion Example
The following code demonstrates conversion from Hex to Decimal:
x=SPACE(20) @ 1,1 GET x READ x=ALLTRIM(x) dec=0 cntr=0 FOR t=LEN(x) TO 1 STEP -1 pod=SUBSTR(x,t,1) valpod=VAL(pod)
DO CASE CASE pod="A" valpod=10 CASE pod="B" valpod=11 CASE pod="C" valpod=12 CASE pod="D" valpod=13 CASE pod="E" valpod=14 CASE pod="F" valpod=15 ENDCASE dec=dec+valpod*16^cntr cntr=cntr+1
ENDFOR WAIT WINDOW ALLTRIM(STR(dec))
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.
@ WROWS()-(3/FONT(1)),0 to WROWS(),WCOLS() ; PATTERN 1 ; PEN 6, 8 ; COLOR RGB(192,192,192,192,192,192) @ 0,WCOLS()-(6/FONT(7)) to WROWS(),WCOLS() ; PATTERN 1 ; PEN 6, 8 ; COLOR RGB(192,192,192,192,192,192)
Colin Keeler - 01/05/94
Make Readonly SQL Cursor writeable
PROCEDURE editcurs PARAMETER lccursoralias PRIVATE lnworkarea, lctmpdbfname, lctmpcur, lncurrarea IF PARAMETER() = 0 lccursoralias = ALIAS() ENDIF lncurrarea = SELECT() SELECT (lccursoralias) lnworkarea = SELECT(0) IF AT(".TMP", DBF()) > 0 SELECT 0 lctmpdbfname = DBF(lccursoralias) USE (lctmpdbfname) AGAIN ELSE SELECT * FROM (DBF(lccursoralias)); INTO CURSOR lctmpcur; WHERE .T. lctmpdbfname = DBF("lcTmpCur") ENDIF USE (lctmpdbfname) AGAIN IN (lnworkarea); ALIAS (lccursoralias) USE SELECT (lncurrarea) RELEASE ALL LIKE lnworkarea, lctmpdbfname, lctmpcur, lncurrarea RETURN
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:
cCurFile = SYS(2005) SET RESOURCE OFF USE &cCurFile exclusive
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:
Color Palette Database Designer Form Controls Form Designer Layout Print Preview Query Designer Report Controls Report Designer Standard View Designer
Next, you want to locate the Form Controls toolbar and delete it. Use the following commands.
DELETE FOR ID = "TTOOLBAR" AND NAME = "Form Controls"
Now pack the table and close Visual FoxPro and reopen it to activate the new resource file
PACK QUIT * to close Visual FoxPro Restart Visual FoxPro
(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:
CurFile = SYS(2005) SET RESOURCE OFF USE &cCurFile EXCLUSIVE BROWSE
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:
DELETE ALL FOR ID = "WINDBROW"
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.).
=a_date-DOW(a_date)+the_dow
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:
RETURN(THIS.ValueToReturn)
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:
DO FORM ABC TO xyz
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:
IF NOT "Support"$VERSION(1) * do whatever ENDIF
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.
SELECT field1,field2,...fieldn ; COUNT(*) AS dups ; FROM table ; GROUP BY field1,field2,...fieldn ; HAVING COUNT(*)>1 ; INTO CURSOR whatever
Colin Keeler - 04/26/94
WAV files, 2 Ways to Play Them
Here's one way:
dimension file_list(1) =adir(file_list,'c:\windows\*.wav') cMmDll='c:\windows\mmsystem.dll' cMCISendString=RegFn('MCISendString','C@CII',cMmDll) cRetn=space(144) for i = 1 to alen(file_list,1) reply=msgbox('Play ' + file_lst(i,1),'',35) if reply=2 exit else if reply=6 sound='c:\windows\sound\'+file_list(i,1) =CallFn(nMCISendString,'close all',@cRetn,144,0) =CallFn(nMCISendString,'open '+sound+ ; ' type waveaudio alias soundf',@cRetn,144,0) =CallFn(nMCISendString,'play soundf from 0',@cRetn,144,0) endif endif endfor =CallFn(nMCISendString,'close all',@cRetn,144,0)
Here's a better way:
SET BELL TO "wavefile.wav",1 ??CHR(7) SET BELL TO
Colin Keeler - 05/09/94
Copyright ?
1996-97 Pro WEBDesign
/ Gustavo - webfox@cyberservices.com
All Rights Reserved
This Page was Launched on Thursday, December 5, 1996