DoCmd, Eval, SetVar, DataToClip, RequestData
These methods all let you drive VFP from a distance. They're methods of the VFP Automation server. DoCmd, Eval and SetVar let you execute various VFP commands and functions. DataToClip and RequestData take data from an open table and put it on the clipboard or in an array. You can use these methods from within VFP (referencing them through the _VFP object), but they're far more useful when you've created an instance of the VFP Automation Server from some other application. These functions are typically not used from within a FoxPro program, but rather within the code of another application that calls VFP as an Automation server. Just as we can call Word or Excel to perform their magic for us, we can call on FoxPro from these languages.
Usage |
cEmptyString = oApp.DoCmd( cVFPCommand ) uResult = oApp.Eval( cExpr ) cEmptyString = oApp.SetVar( cVarName, uValue ) |
Example |
oVFP = createobject("visualfoxpro.application") oVFP.Visible = .T. && So we can see it * Change the background so we can tell the two apart. oVFP.DoCmd("_SCREEN.BackColor = RGB(64,128,128)") oVFP.DoCmd("USE [" + ADDBS(_SAMPLES) + ; " Data\Customer]") ? oVFP.Eval("DATE()") && Returns DATETIME()! not date oVFP.SetVar("lnRecCount",oVFP.Eval([RECCOUNT("CUSTOMER")])) ? oVFP.Eval("lnRecCount") && Shows 92 records |
Usage |
uResult = oApp.DataToClip( [ cAlias | nWorkArea ] [, nNumberOfRecords ] [, nDataFormat ]) aArray = oApp.RequestData( [ cAlias | nWorkarea ] [, nNumberOfRecords ] ) |
Parameter |
Value |
Meaning |
cAlias |
Character |
The alias from which to gather data. |
Omitted |
If nWorkArea is also omitted, gather data from the current work area. |
|
nWorkArea |
Numeric |
The work area from which to gather data. |
Omitted |
If cAlias is also omitted, gather data from the current work area. |
|
nNumberOfRecords |
Numeric |
The number of records to place on the clipboard or in the array. |
Omitted |
Put the current record and all remaining records on the clipboard or in the array. |
|
nDataFormat |
1 (or 2) or omitted |
Separate fields with spaces. |
3 |
Separate fields with tabs. |
|
aArray |
Array |
An array to hold the specified records. |
uResult |
Numeric |
The number of records returned. |
Character |
The empty string. Returned only when the specified cAlias is not used or nWorkArea has no table open. |
Example |
* Continuing from the example above ? oVFP.DataToClip() && Shows 92 records copied aData = oVFP.RequestData() && Loads aData with records ? ALEN(aData) && 1104 elements ? ALEN(aData,1) && 92 rows ? ALEN(aData,2) && 12 fields each |
See Also |