下面的示例演示了如何从 Visual FoxPro、一个帮助文件以及 Word Basic 使用 Fpole.dll 中的函数。
MYDLL = "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll"
DECLARE integer SetOleObject in (MYDLL) string
DECLARE integer FoxDoCmd in (MYDLL) string,string
DECLARE integer FoxEval in (MYDLL) ;
string, string @,integer
=SetOleObject("visualfoxpro.application")
?FoxDoCmd("wait wind 'test' timeout 2","")
?FoxDoCmd("modi proj xx2 nowait ","")
?FoxDoCmd("close all","")
clear dlls
帮助文件示例
RegisterRoutine("Fpole.dll","FoxDoCmd","SS")
HotSpotText!FoxDoCmd("DO (HOME() + 'myprg')","at")
Declare Sub FoxDoCmd Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll" (cCommand As String, cOptions As String)
Sub MAIN
FoxDoCmd "USE (HOME(2) + 'Data\Customer')", "i"
FoxDoCmd "_CLIPTEXT = customer.company", "i"
EditPaste
End Sub
这个示例提供了一个对话框,用户可以从一个列表中选择一个客户标识 (ID)。相关的公司名称和合同将插入到 Word 文档中。
'
声明Fpole.dll
函数.
'--------------------------------
Declare Sub SetOleObject Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cApp As String)
Declare Sub FoxDoCmd Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cCommand As String, BringToFront As String)
Declare Sub FoxEval Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cExpression As String, cBuff As String, nLen As Integer)
Declare Sub CloseIt Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll
Sub MAIN
Dim cBuffer$
cBuffer$ = String$(50, " ")
Dim aCustID$(5)
aCustID$(0) = "BLONP"
aCustID$(1) = "CHOPS"
aCustID$(2) = "ISLAT"
aCustID$(3) = "LETSS"
aCustID$(4) = "SEVES"
cboCustID = 0'1st element in the array
Begin Dialog UserDialog 404, 150, "Calling Visual FoxPro with Fpole.dll"
DropListBox 44, 33, 160, 108, aCustID$(), .cboCustID
Text 15, 14, 268, 13, "Choose a Customer ID from the list.", .Text2
Text 15, 61, 231, 13, "Then Choose OK to insert the ", .Text4
Text 15, 78, 215, 13, "Company Name and Contact", .Text5
Text 15, 95, 141, 13, "into your document.", .Text6
OKButton 298, 76, 88, 21
CancelButton 299, 111, 88, 21
End Dialog
Dim dlg As UserDialog
nButtonChoice = Dialog(dlg)
'
如果用户按“取消”…'--------------------------------
If nButtonChoice = 0 Then
Goto EndOfSub
End If
'
自动执行Visual FoxPro
'-----------------------
Print "Opening Visual FoxPro"
SetOleObject "visualfoxpro.application"
FoxDoCmd "USE (HOME(2) + 'Data\Customer')", "i"
FoxDoCmd "LOCATE FOR cust_id = " + Chr$(39) + aCustID$(dlg.cboCustID) + Chr$(39), "i"
Insert "Customer ID" + Chr$(9)
FoxEval "cust_id", cBuffer$, 50
Insert RTrim$(cBuffer$)
InsertPara
Insert "Company:" + Chr$(9)
FoxEval "company", cBuffer$, 50
Insert RTrim$(cBuffer$)
InsertPara
FoxEval "contact", cBuffer$, 50
Insert "Contact: " + Chr$(9) + RTrim$(cBuffer$)
InsertPara
Print "Closing Visual FoxPro"
CloseIt
Print " "
EndOfSub:
End Sub