How to run App with right Version / SP [June 2, 2009 07:18]A commonly problem seems to be to run an app with the VFP Version / SP it is compiled. VFP itself gives not much help on this. But some little compiler commands like #IF and #DEFINES will do the trick.
How do I know if report is printed [May 8, 2009 02:02]When printing, sometimes there is a need to know if a report is printed or not. Since we have no simple way to see if something is realy printed we can at least check if the user send a complete report to the spooler. This article deals with the way to solve this problem with and without object assisted reports (aka listeners).
Data Conversion / Merge with Update and Insert [July 24, 2007 07:54]Over the years I've seen many people ask how to take a new set of data and use it to update an existing set of data. I've done various versions of this kind of code. Usually this is done with a very large complex program that involves lots of seeks, scan, append blanks and replace commands. Here's my latest approach.
Dataset Databinding and Formatting Not Refresh [February 27, 2007 00:28]I notice that when you use Databinding with format string, it seems that the format was not refresh in realtime. This can be solved by hooking to BindingComplete Events and force re-evaluated the data.
Class to close any cursors created after it was instantiated [January 31, 2007 15:52]Generally, datasessions serve this purpose - they create an isolated environment where our code can run and use tables, cursors etc as it pleases, without disturbing other code. Sometimes wee need a little more granularity - to have a routine which may create any number of cursors, open additional tables, and close them all when done, without closing any previously open ones. This simple class will do just that.
Running under Terminal Services [January 20, 2007 04:17]Is the application running under TSE?
Validating that a path and filename is usable [November 3, 2006 11:43]This presents a function to validate that a path and filename are valid to use. Recently, it became neccesary to validate that the user entered a usable file name. There are certain characters that can not be used in a file or folder name. Not to mention invalid path to the files. The code I present here solves the problem.
Auto-Dock Tool Windows in VFP [August 11, 2006 13:53]Here's a tip to help keep useful windows available and where you want them. Create a program called devUtils.prg and store it in the VFP home folder. Also, create a file named Config.fpw there. In the Config.fpw file, add the following text: Command = DO devUtils.prg In the devUtils.prg, add the following code: *JCJB* Setup useful OKLs. ON KEY LABEL F12 DO DockWindows IN devUtils *JCJB* Dock the Tool windows and open the Project. DO DockWindows PROCEDURE DockWindows *JCJ...
Duplicating inserts and updates on two databases for two tables [January 19, 2006 10:08]I'm sure (developers though) you have already lived a situation like this: having 2 databases (with the same tables) and need to "replicate" the data, each time an INSERT or UPDATE is made. It seems very simple, until someone add a new feature: "Oh, by the way, all the fields are equal, except the Number, that should remain sequential for each table". Now, as you can see, you must forget the INSERT FROM... clause.
How to pass cursor between two VFP datasessions (without using XML) [January 3, 2006 06:03]Example of passing cursor as object across VFP datasessions boundaries. Story is simple. We store cursor (or part of it) into custom object properties using one function 'cur2obj', then we pass that object reference at our own terms to another session object (or form with private datasession), where we use counter function 'obj2cur' to restore original cursor data from that object but this time in receiving session. Since temporary cursor/arrays are used to prepare/store cursor data, we shou...
Custom Page or Printer Form on Crystal Report and different machines [December 11, 2005 19:11]When you use Custom page in Window 2000,XP and higher, we have to create first our custom form on the print server. Using Crystal report, we can easily use the custom paper. Example we can create 1/2 of the letter Size or simply 8.5by5.5 paper. This works fine in crystal, but the problem occur when you use different printer model especially on a different machine. This is because crystal report same printer form ID instead to form name. So if you create 8.5by5.5 form on machine1 and machine2 i...
Inheritance tutorial [October 7, 2005 23:36]This is a step-by-step tutorial to show inheritance, specifically in Visual FoxPro forms, as a guidance for people who are not familiar with inheritance in general, or who don’t know how to implement it in Visual FoxPro. The basic idea of inheritance is that all your forms, or several of your forms, obtain their properties and methods from a "base form". It is possible to do changes only once, in your "base form"; the changes will be propagated to all your forms.
CHM help file shows error messages instead of help pages [October 6, 2005 19:12]Due to a recent Windows security fix, users can no longer access a CHM file on a server. The table of contents appears, but the individual pages are replaced by error messages. Access to CHM files in specific folders can be explicitly allowed through special registry settings.
Getting the names of parameters in the parameter list at runtime. [July 12, 2005 11:18]Sometimes the developer needs to determine the names or values of the parameters in a parameter list during runtime. The following routine returns the name of the parameter based on it index into the list of parameters. It is a refined routine first conceived by Hugo Ranea. Thanks Hugo.
Running a VFP app as a Service on Win 2003 & XP Pro Systems [June 14, 2005 18:03]Running a VFP app as a service is a snap! Just download the Windows 2003 Resource Kit from Microsoft at... http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en and follow the instructions in this FAQ's description.
Save General Data to a File [June 11, 2005 13:20]This code and information is designed to put you on the right path to retrieve the stream of data from a general field and store it into a file. I have put together useful sites and code snippets that will help you retrieve data for BMPs, JPGs and PDFs. Using these general techniques you should be able to get data for any file type.
Progress Bar Class Example [May 12, 2005 18:25]We often find the need for progress indication (read: eye candy) in our applications. While many different solutions for progress bars are available, I like having a pure VFP solution that runs in its own process. So here is an OLEPUBLIC Progress Bar Class (designed to be compiled into a COM Server EXE). Its chief advantage is the ability to run smoothly even when your application is crunching on a single line of code.
How to keep focus in Last Control that have it [April 20, 2005 14:58]Many times you want the Last Control in your form to keep the focus after you made some operations that cause LostFocus of that control (Clickig on Button in the form or something similar). This code is tested on VFP 8 SP1, but I am sure that there will be no problems in other version of VFP.
Printer Pooling for DOS Printing in WIndows XP [October 14, 2004 10:13]A printer pool is a physical group of identical printers (printers of the same model or that have a similar emulation which allows them to share the same print driver) that are connected to a single computer via different logical ports. When configured as a printer pool the group of printers behave as one printer. In Windows XP, when a user sends a print job to the printer, the job goes to the print queue first. Then the print server polls the printer to see if it is available. If it is, the jo...
Why non read-only grid behaves as read-only [September 6, 2004 23:56]One of the common problems with the grid control is that it doesn't like columns controlsources to be specified without table prefix. Quite often in this situation grid starts to behave as read-only. One simple way to avoid it - specify column's controlsource in TableName.FieldName manner and not just FieldName.
How to create a custom script with intelliscript [June 4, 2004 07:00]Custom scripts are different from scripts that are invoked via a command or function. The big plus to command or function is that custom scripts may invoke everywhere in a line, while command can be invoked only as first word and functions need a "(". There are some problems to write a custom script with intellisense. It is even uneasy to duplicate the examples zloc and zdef that ship with VFP8.0 and beyond. This FAQ points to the steps to create a custom script. It will use a IF .. ENDIF st...
Least common multiple and greatest common factor [May 30, 2004 20:51]The code shows how to quickly obtain the greatest common factor, and the least common multiple. Both functions are used when manipulating fractions, among others. Several methods are possible; the method usually taught in school involves prime numbers, but this code will execute much faster (and it is much simpler) than the use of prime numbers.
How to determine Debug or Release Mode [February 10, 2004 08:52]This FAQ will show you how to extract a compiler emitted attribute to determine if the current assembly has been built using a Debug or Release configuration and set debug specific JIT compiler settings for Release builds. The information is current for the .NET Framework 1.1, documentation version 1.1.0.
A faster alternative - Replace your OptionGroups/ComboBoxes by TextBoxes. [June 6, 2003 10:15]I've been using FoxPro since 2.5 DOS and I used a lot of TextBoxes to set something like "[Y]es or [N]o". When I started to use VFP, I changed this kind of control to OptionGroups. It looks great, but the users complain a lot arguing that pressing "Y" or "N" is much simpler (and faster) than using this new control. So, I decided to go on using the TextBoxes for this sittuation. Look at it and learn the easy way to control it!
Terminal Server Auto Logon [May 12, 2003 10:35]This describes how to assign a valid userid and password for network authentication when using Terminal Server.
Using Oracle SPs to Insert and Update Data from VFP [April 11, 2003 17:44]This demo code will connect to Oracle [using your ID and password] to create a table of Presidents, a trigger, a sequence and some stored procedures. The stored procedures can be called to insert and update data in the Presidents table. Three of the methods in the VFP class will pass data values to the Oracle procedures which will either be inserted into the table or update existing records in the table. The update SPs will also return a value equal to the number of records updated.
How to Change a file's Attributes (With only the Window API)? [April 3, 2003 17:42]Here is a way to set a file's attributes (System, Readonly, Hidden, Archive, etc) without requiring any component other than the standard Windows API.
How do I retrieve special folders without relying on Shell.Application? [December 19, 2002 19:16]Shell.Application is a great extension to the Windows environment, that by now we really ought to be able to rely on finding. Unfortunately, there are still a lot of retail Win95 and WinNT 4.0 SP3-6a client stations that have never had the Active Desktop Shell extensions installed; in addition, the support for Common System Location IDentifiers (CSLIDs) is notably incomplete under Win95, Win98 and WinNT. There is a downloadable, fully redistributable .DLL called SHFOLDER.DLL that extends suppo...
How do I get the path of special folders from Windows [December 13, 2002 15:19]Windows provides us with a common set of standard special folder names which are used throughout to refer to Common System Location IDentifiers (CSLIDs) - the Shell.Application object provides us with a means of retrieving them by name - in fact, it will return Shell Folder objects for each of the named special folders supported by our current version of Windows
Spaces in file and directory names [December 2, 2002 16:28]This FAQ describes some considerations to take care of when using spaces in directory names when being used with macro substitution.
How to check if drive is ready [November 26, 2002 19:08]It's a good idea to make sure that there is media in the removable drive before accessing it and display user friendly message instead of system error message if drive isn't ready. It can be done using Windows Scripting Host (WSH) or with help of Windows API.
Forms with Grids and printing reports [November 9, 2002 22:33]If you print reports from forms, which have a grid on it, and the grid has focus while printing the report, you may notice, that the report alias switches to grid's RecordSource instead of alias used to produce this report. I would not speculate, if this is a bug in VFP or it's by design, but you should be aware of this problem and always move focus to another object prior to printing the report.
Recommendations for memory configuration for FPDOS/FPW under Win32 OS [November 7, 2002 05:58]Both FPDOS and FPW are capable of being run under various Windows uperating systems; their performance cna be radically improved, and fewer memory-related problems encountered, depending on the type and amount of various memory settings under the operating system for the executable. This FAQ recommends some base memory settings for these operating settings.
How do I invoke the SelPrint method of the Richtx32.OCX control to print RTF content [November 6, 2002 06:01]The RichTextEdit control provides a mechanism to print the text stored in the RTF control, SelPrint. This discusses the steps necessary to invoke SelPrint from within VFP outside of the report writer. It specifically addreses the issue of how to obtain a device context for the Windows Printer to use to print the RTF content.
What is a GDI printer, and what's the matter with using one? [November 1, 2002 15:29]More and more low-end printers have started relying on the Windows Workstations graphic services to render their output. While this lowers the cost of the printer slightly, there are distinct disadvantages to them in many cases. This FAQ deals with what exactly a GDI printer is, what the drawbacks of using one are, and how this affects applications that use them.
Finding a value right before and right after a seed value. [September 11, 2002 20:35]I was reading SQL Magazine and an article by Brian Moran solved a problem I had. The problem was "How do I get the record right before and right after some seed value?" His solution was a creative use of the MIN and MAX functions of SQL. I paraphrase his TSQL code into VFP:
Installing Internet Information Server (IIS) on Windows 2000 (Win2k) [September 9, 2002 07:00]Instructions on installing and securing Internet Information Server on Windows 2000. It is recommended to read this even if your IIS is running smoothly on your Windows development/server machine. Tools are applicable to Windows XP and IIS 6.0. Notice that IIS is present in Windows 2000 Pro and Server versions and in Windows XP Pro and Server versions, but is not available in Windows XP Home edition.
How to show a toolbar in a top level form at startup [June 21, 2002 05:00]This FAQ article describes how to show a toolbar in a top level form at startup. This should be a simple task, but when adding the code to show a toolbar in the form's Init event method, the toolbar still shows up in the _SCREEN and not in the top level form.
Show seconds in a readable format [June 7, 2002 09:18]If you need to check elapsed time with seconds() or a datetime value, this function allows you to display the elapsed time in a human-readable format, that is, hours:minutes:seconds, instead of the total number of seconds. Just pass a number of seconds as a parameter.
How to add custom properties to SCATTER NAME-like object for use with GATHER NAME command [May 29, 2002 09:45]Instead of trying to add properties with some third-party tools like ADDPROP5.FLL to the native object created with SCATTER NAME command you may try to approach this problem from the other side. You can replace the native SCATTER command with your own function MYSCATTER which may work on any area and create the object from one of standard VFP classes and use its native .AddProperty method.
256-color icons in EXE application compiled by VFP [May 28, 2002 12:06]VFP does not support 256-color icons as project's icon (icon displayed for EXE in Windows Explorer). But 16-color icons usually looks ugly and too simplified. Here is an approach that allows organize 256-color icons for VFP EXE application. The approach is based on use of Resource Hacker application. You can download it from following URL: http://download.techworld.cz/software/resourcehacker.zip (UPDATED: original link does not work for some reason. Let me know if this one also does not ...
How do I avoid the annoying Outlook dialog sending Outlook automation or MAPI email? [May 12, 2002 16:51]This is a WSH-based solution to automating the dialog invoked by Outlook's security manager whenever VFP is used to send an email via Outlook automation or MAPI automation. The sample is done using VBScript; JScript would work just as well. It is dependent on the functionality in Wscript.Shell from WSH version 2.0
RASDial doesn't but says so [May 9, 2002 00:36]A RAS-Connection can be "virtually" established when in fact You are still local. IE's OFFLINE-setting kept me busy for some time and made me look at wrong places. Because my protocols indicated that a RAS-Connection has been successfully established and User-Auth. has been done, I have been searching for problems that were not existing. Here are a few lines that hopefully save some of You a lot of time and frust.
How to make SQL Pass-Through cursor updatable [April 9, 2002 13:00]The SQLEXEC() function in VFP allows downloading of data from any data source through ODBC. Unlike remote views, SQL Pass-Through approach does not provide default (automatic) settings in the returned cursor to update data on the server after changes in the cursor at the client side. Anyway, it is possible to customize required properties to organize updating. First of all, it is recommended to read chapters about SQL Pass Through commands in the MSDN, specially, chapters that explain propert...
Force positioning of text cursor by right mouse click in EditBox and RTF ActiveX controls [February 8, 2002 08:39]There is a situation often when we need some way to position a text cursor in the text of Editbox or RTF ActiveX controlwhen right click on the control. For example, we want to display a shortcut menu on right click. In menu, user select an option that insert some text into the control on place of current position. However, right click on the control does not change the text cursor position, that confuse users. It would be good to right click, cursor moves to the clicked point and then menu disp...
How to freeze (lock) a column in the grid without use of split bar [February 8, 2002 08:39]The approach is based on a simple principle. LeftColumn property of the grid represents a column that is currently the leftmost visible column in the grid with current horizontal scrolling. As we scroll the grid horizontally, this property changes. We can assign this number to the ColumnOrder property of the column we want to hold and that’s all: this.Columns(1).ColumnOrder = this.LeftColumn You can use this in the Scrolled and AfterRowColChange events of the grid. However, there is a...
SPT cursor fetching and progress displaying for SPT cursor downloading [February 5, 2002 12:55]SQL Pass Through commands often can take a lot of time for running and returning the result set to the client. It is often usefult to show a progress bar in case of such lengthy process. Also, FetchAsNeeded option, available for views, could be very useful for SPT cursors as well. However, how we can open SPT cursor and set FetchAsNeeded option for it? Here is a sample code for opening the cursor in "FetchAsNeeded" mode, as well as a description of approach for organizing the progress bar for...
How to display Tool Tips for different parts of the Grid? [February 1, 2002 12:08]In VFP6 Grid value of the ToolTipText property of controls is displayed only for the entire grid or for current control when mouse is over it. Becuase there are a lot of parts in the grid, it is often useful to display tool tip for different parts separately. Unfortunately, VFP interprets grid as a single control, displayed tool tip appearance for grid is not changed immediately even when ToolTipText property is changed, until mouse is moved out of the grid and returned into the grid into requir...
How do I use the Amyuni PDF Converter in VFP? [January 31, 2002 15:14]This code illustrates one way to use the Amyuni PDF Converter with VFP. Adapted from the documentation provided with the product. Tested under VFP6 SP3 using the Amyuni demo product which can be downloaded from www.amyuni.com. (This is an update to the original FAQ #658 which was posted on 14-Aug-2000)
How to Create & Update a Graph in a Form and Report. [January 31, 2002 02:06]This article shows by example how to create and update a graph on a form and print graph report. You can use DO (_GENGRAPH) for Cereate new graph. You can use APPEND GENERAL command in Visual FoxPro contains a new clause (DATA) that allows you to send data to a Microsoft Graph object programatically in a General Field. You can display graph in a form and report.