FoxPro Q&A
Culled from the Internet
|
Al. You can use the TYPE() function to test for the variable’s existence. For example:
|
|
IF TYPE(”IMy Variable”) # U”
|
Q.
|
I am allowing the user to specify the name of a file. I am
|
using PUTFILE() to allow the user to enter the name, but when
|
• the variable exists
ENDIF
|
they select a file that always exists, I always get a warning about overwriting the file. This happens no matter the setting of SET SAFETY. Is there an option?
A. PutFile() invokes the standard windows Save Dialog. One way around this is to use the common dialog OCX control. By
|
Or you can check for the TYPE()
=
“U” if you want to see if a variable does not exist. Be sure to put quotation marks around the name of the variable, as in the example above.
(Mike Beane, CISID: 71175,3160)
|
placing the OCX control on a form, you can invoke the ShowSaveO Method of the control. If you elect to choose a file that already exists, a dialog *wiIl not* appear. Once you have made a file selection, this will update the
FileName
Property of the OCX control:
ThisForm.OleControll .ShowSave()
If NOT Empty(ThisForm.OleControll .Filename)
*
save the file
|
Q.
I would like to automate a rebuilding process and would be reading the index tag and expression from a table. However, I don’t see any way of determining the order of the expression or what type of index (unique,
primary,
regular, candidate). Any suggestions?
Al. (The following was sort of an on-line conversation between
Doug
Hennig (DH) and Gary DeWitt (GD), I’ve edited their
|
Endif
|
responses together to make a more continuous conversation. Though they disagree with one another in many ways, I found
|
Q. I would like to add the button ‘Dial’ to my VFP grid with names and telephone numbers. After prssing
|
both methods valuable
-
Bill)
|
my modem should dial the number.
|
DH -The following are the functions you need to get the index
|
Al. If you are working on NT or Win95 you can use
|
information necessary to recreate indexes (I won’t bother
|
MSCOMM32.OCX that ships with VFP.
|
explaining them here; you can look them up in the VFP Help):
|
A2. MSCOMM32.OCX only installs if your running Win95 or NT,
|
PRIMARYO
|
not on Windows 3.1. If so, try this routine using the Window
|
CANDIDATE()
|
API. It works well under 3.1, pretty stable on 95 & NT. You’ll
|
UNIQUEO
|
need to provide the parameters starting with THISFORM.
|
KEYO DESCENDINGO
|
*
write data to the serial port.
SET LIBRARY TO ‘FOXTOOLS.FLL’
•
|
Assumes that the number to dial is stored in
|
*ThisFormCallnumber
|
TAGNO()
TAGO
FORO
|
M.Output
=
“ATDT”
+
ThisForm.CallNumber
+
‘AM’
+
CHR(13)
|
IDXCOLLATE()
|
LOCAL Iccomport, lcdstring, Inport,
|
|
Iccomport
=
LEFT(THISFORM.ComPort,4)
lcdstring
=
m.output
OPENCOMM
=
REGFN(”OPENCOMM”,”CII”,’I,’USER.EXE’)
|
Automating the index rebuilding process is a *lot* more difficult to do properly than it was in 2.x. Here are just a few of the
|
WRITECOMM
=
REGFN(’WRITECOMM’,’ICI’,’I’,’USER.EXE’)
|
“gotchas” that can hurt you
when recreating indexes:
|
CLOSECOMM
=
REGFN(’CLOSECOMM’,’I’,’I’,’USER.EXE’)
|
|
LNPORT
=
CALLFN(OPENCOMM,LCCOMPORT,100,100)
open comm port
x
=
SECONDS()
|
Most developers use DELETE TAG ALL before recreating
indexes to eliminate tag bloat and dump indexes that are no
|
DO WHILE SECONDS()
-
Xc I
|
longer used. Unfortunately, in VFP, this has the side effect of
|
ENDDO =CALLFN(WRITECOMM,LNPORT,LCDSTRING,LEN(LCDSTRING)) &&
send string to modem mTime
=
SECONDS()
|
deleting all your persistent relationships and their rules. If the
CDX file is missing, VFP won’t let you open the table to recreate
the indexes if the table has a primary key defined. This is kind
|
DO While INKEY(”HM”) =0 AND SECONDS()
-
mTime
<
15
|
of a Catch-22 situation: you can’t open the table because
the
|
**
|
wait for KeyPress or timeout
|
ENDDO
M.Output
=
~ATHOAM
+
CHR(13) && hang up modem
|
primary key is missing, and you can’t recreate the CDX with the
primary key because you can’t open the table.
|
=CALLFN(WRITECOMM,LNPORT,LCDSTRING,LEN(LCDSTRING))
|
|
=CALLFN(CLOSECOMM,LNPORT)
|
GD
-
That’s actually pretty easy to work around. Simply open
|
X
=
SECONDS()
DO WHILE SECONDS()
-
X <2
ENDDO
RELEASE LIBRARY ‘FOXTOOLS’
|
the table with FOPENO, delete the
CDX flag and the DBC backpointer, open the table normally and reindex, then open
again with FOPENO and stick
the backpointer back in. As long
|
(Ed Vanduyne, CIS ID: 75740,3071)
|
as the table doesn’t think it has a DBC you can open it all you want.
|
Q.
|
How can I test to see
if a variable exists?
|
|
(Con’t, page 8)
|