Moving from dBase/ FoxPro to Visual FoxPro 6
(May download Poor People's Dummy VFP6 v0.0 , a 20-KB freeware by me)
(May also download Visual FoxPro 6 Runtime Freeware, if needed)

(Warning: This article talks about only a few gallons of water out of the ocean called Visual FoxPro 6)

If you are a programmer in dBase/ FoxPro/ FoxBase, then shifting over to Visual FoxPro is both easy and beneficial. The first advantage is: VFP6 is such a vast language that there will be available to you many functionalities as you learn it better, while your old programs written in those older languages will run almost as well in VFP6. The second advantage is that a fully functional setup package for your prepared program, of which you become the sole legal owner, can be easily obtained by using the Setup Wizard in VFP6. This means that your users neither need to buy & install VFP6 themselves, nor you need to be tempted to immorally offer your copy of VFP6 illegally to your users. Thirdly, in VFP6 you can easily form self-executable or command files (with the extension .exe or .com) that needs just to be double-clicked to run your program, instead of teaching the user to run it from the language platform etc.!

To get VFP6 in your computer, get Microsoft Visual Studio 6 installed in it. This MVS6 has VFP6 in addition to Visual Basic, Visual C++ etc. The first CD is enough for the working environment to be installed, while the next CDs contain the MVS6 Help system called the MSDN collection. Click on Programs in Start Menu, then click on Microsoft Visual Studio and then on Microsoft Visual FoxPro to start it (create a shortcut to the Desktop if you like). Then close the so-called Welcome Screen just out to confuse you, better after clicking at the Do not show this screen again option. FoxPro users will arrive at their familiar Command Window -- if not observed click at Window, then at Command Window. dBase users need to know that the square-sized command window at the right-middle side of the screen is the place where you can type and view your VFP6 commands, and is the equivalent of the Dot-Prompt in dBase. Now enter Modify Command MyProg or Modify File MyProg.prg etc. to write your program in a resulting program editor. You can create and modify database files etc. similarly (note that the total number of simultaneous work-areas is not limited to 20 here). After you've completed making (and checking by entering Do MyProg etc.) your program, make the self-executable program by invoking the Project Manager. To do this, enter commands like Modify Project MyProg. In the resulting project manager window click at the Code button, then click at the Add button, ensuring that the Programs icon remains selected, and then select the master program file (say, the MyProg.prg file) in the file browser. You need not add the other program files, format files etc. referred by the master program file: the manager will do that for you. In general, you should not add your database or document files into the project, as then they may become non-modifiable during the program operation. Now you may click at the Build button, and then choose the Build Executable option to build the MyProg.exe executable file (you may also click at the lower version button to add some programmer & version information into the executable file.)

After building the executable file that thus incorporates all your .prg and .fmt files etc. (in an unreadable form), but does not in general include the .dbf or .txt files etc., copy this .exe file and all the associated database (.dbf) and document (.txt) files etc. to the proper working folder of the application (say, C:\MyProg, in which the users will keep your application). Do not forget to take any of your required files: may check that by double-clicking that .exe file in this new location to see whether your application runs properly. If it does, invoke the Setup Wizard by clicking at Tools, then at Wizards, and then at Setup. In the Setup Wizard Screen, specify the program directory (e.g., C:\MyProg) where the program presently lies, specify the components necessary amongst which Visual FoxPro Runtime is a must, specify Websetup (Compressed) as the Disk Images option (that gives a single executable setup file that can be transferred to a CD and then can be double-clicked in another computer to install the application), and specify a separate Disk Images Directory i.e., folder (say, C:\SetupMyPr) where the setup file transferable to CD will be kept. In addition, you need to also specify a Default Destination Directory, which is the folder that the setup program will create in your user's computer and put therein your application files. After specifying everything and clicking Finish, wait for a few minutes for the dust to settle, then click at the Done button, and Wow! You have a full-fledged installer (setup) executable file called websetup.exe (rename the websetup part of the name, if you so like) in a folder (say, C:\SetupMyPr) in your hard disk, which when transferred to a CD or website can install your application in any other computer, and over the sale and/ or distribution of which you have the full, exclusive, legal rights!


Frequently asked Questions:

In dBase/ FoxPro I could manage my colors nicely, but here sometimes unexpected colors come! Why?
It's probably because VFP is more rigorous in putting color on screen just as per your instructions. Probably you desired the effect of an @ x, y clear or an @ a, b to x, y clear command, try putting that command in the program file just after a new color setting. However, if you're looking for the milk-white screen to reappear by a set color to   command after you've changed it, well, it simply doesn't happen.

When I run my program by entering Do MyProg, the horizontal geometry is always wrong! Why?
The default font in the development environment doesn't offer equal space for every character (like Arial but unlike Courier New), so you face this problem while running there. When you or your users run it from the runtime environment (by double-clicking the .exe file), this problem isn't faced -- try checking that. Also, inside the program, be cautious about choosing a non-default font.

I'd prefer to have my own application heading to appear on my program window bar instead of 'Microsoft Visual FoxPro'!
It's very easy. Just make a text file config.fpw with the first and the lone line being
Title = My own program title
and then include this file into the project by adding as an 'other-other-all' file in the project manager. Then build again.

I want to let my users run the program in the full-screen (maximized window) mode. Is that possible?
By double-clicking the .exe file you'll always get a normal screen mode. To run full-screen, make and use a link file (shortcut) to the .exe file, and choose the run maximized option therein.

Unlike dBase etc., my users can't append record by pressing downward arrow while browsing a table!
They may append while browsing by clicking at the menu-button Table, then at the Append option. Alternatively, you may have 10 or 20 blank records pre-appended (by code) just before their browsing.

When I put the edit command in my program, with a format (.fmt) file in work, only one record gets edited unlike in dBase etc. How to get multiple record edited in the edit screen?
Instead of the
Edit command, use the Read command (after the Set format to MyForm command line, provided a database-table is already in use). Your user exits this Read screen by PageUp, Ctrl+End, PageDown etc. key-strokes, each of which leaves a pair of unique readkey() values associated with an changed or unchanged record. Thus PageUp leaves a numeric readkey() value of 6 in case of unchanged record, and of 262 (i.e., 256 + 6) in case of a changed record. You are, so, free to design the code so that the user can edit multiple records one by one. (In case of a Read command reading some variables shown by a set of @ a, b get MyVar type of commands also, similar readkey() values exist.)

I am from dBase legacy. I want to know about the functions inkey(), getdir() & getfile(), and the mouse-oriented functions mrow() and mcol() in Visual FoxPro.
The inkey() function is to be used in a line (in the program file) as MyNumVar = inkey(60,'ms') or MyNumVar = inkey(0,'mh'). Here 60 means that the program will wait for only 60 seconds (allowed value 1 to 99 etc.) till the user puts a keystroke or a mouse-click (0 means that it will wait indefinitely). The other part 'ms' means that the keystroke cursor (prompt) is shown, while in case of 'mh' it's hidden. In case the user does nothing and the time elapses, MyNumVar stores the value 0. If she clicks the mouse, the value 151 gets stored. In case of a keystroke, the ASCII number gets stored in case of a character key, while some other numeric values gets stored (as described in FoxPro or VFP6 help) in case of non-character keys. In case of a mouse-click, mrow() and mcol() gives the screen row and column positions (may even be fractions) where the mouse was clicked, by using which you can make your pseudo-buttons or pseudo-hyperlinks (if any)  actually working as per the mouse-clicks directed at them.
The getdir() and getfile() functions are preferably used in the forms of command lines
wanteddir = getdir() or wantedfile = getfile() where the result of the user's selection of folder or file will be stored as character-string pathnames in the wanteddir or wantedfile etc. variables. Similarly, the wantedfont = getfont() sort of command lets the user select an existing true-type font with desired size and type, and stores the selection in the character variable wantedfont, the specifications separated by two commas.

How to get picture buttons here? Can I put picture files in modern formats into Visual FoxPro buttons?
You can get a picture containing button by putting a command line such as
@ 2,19 say "MyInstruction" get pic Picture '@*B MyPict.gif' size 6,25
(OR  
@ 4,16 say "MyInstruction" get butt Picture '@*B MyButt.gif' size 2,12)
that must obviously be followed by a
read or a clear gets command. Here pic (or butt) is a pre-defined variable (say, as, pic = "A" or butt = "B"), and MyPict.gif (or MyButt.gif) is any pre-existing (obviously may be modern-format) picture file, the contents of which (e.g., a butterfly or a OK sign) gets displayed on the button. You may also have that picture file included into the project by adding it as an 'other-other-GIF' file in the project manager. In case of a consequent read command, the character variable (e.g., pic) will contain the null value "" in case the user mouse-clicks or presses Enter, no matter its pre-defined value (e.g., "A"). Upon pressing Esc, however, the pre-defined value remains.
You may also have two or more such picture buttons (with separate associated pre-defined character variables pic1, pic2, pic3 etc.)  activated simultaneously by a single consequent
read command. The program can determine which button was mouse-clicked by the user by noting which character variable has got thus 'nullified', with other variables keeping their pre-defined values intact. 
You can also have buttons showing desired prompts without taking recourse to picture files. To do that, use a command of the sort
@ 4,16 say "MyInstruction" get butt Function '* MyPrompt' size 2,12 (keeping OK or Cancel etc. in place of MyPrompt. Here, however, upon clicking the button, the character variable (e.g., butt) will contain the character string value "MyPrompt" (e.g. "OK") instead of null value.
A combination of one or more ordinary
@ a, b say "My Instructions:" get variab1 type of commands ending with such a picture/ function button showing the OK sign followed by a read command gives an obvious way to offer your users a mouse-friendly way of putting in their textual inputs.
You may click here to download (~20 KB) twenty number of .gif picture files kept together, showing the OK, Cancel, Save etc. signs. Such files may be made by selecting the Text Tool in Windows Paint, then typing the required text there, then copying it away by using the selection tool, to be pasted into and saved in a picture-manipulating software such as IrfanView.
 

Subscribe to the Wrox Peer to Peer Visual FoxPro Developers Community

Back to main page