Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel variables and VFP
Message
De
02/09/2004 20:17:21
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00937401
Message ID:
00939017
Vues:
37
This message has been marked as the solution to the initial question of the thread.
>I am beginning to wonder if the problem might be that "build" is skipping some steps,
>after all in this article
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfoxgen7/html/vfpandcom.asp?frame=true#vfpandcom_topic08
>
>1. build is only one step
>
>
>IF FILE("myclass.dll")
>   DECLARE integer DllUnregisterServer IN myclass.dll  && a missing step?
>   DllUnregisterServer()
>   CLEAR DLLS
>ENDIF
>BUILD PROJECT myserver FROM myclass
>BUILD DLL myserver from myserver recomp   && the DLL is called myServer
>*now test this COM server:
>ox = CreateObject("myserver.myclass")    && create the server object
>ox.mydocmd("USE home(1)+'samples\data\customer'")    && use a table
>?ox.myeval("RECCOUNT()")    && get the record count
>
>DEFINE CLASS myclass AS session OLEPUBLIC  && the class is myClass
>   PROCEDURE MyDoCmd(cCmd as String) as Variant ;
>         helpstring "Execute a VFP cmd"
>      &cCmd    && just execute parm as if it were a fox command
>   FUNCTION MyEval(cExpr as String) ;
>         helpstring "Evaluate a VFP expression"
>      RETURN &cExpr    && evaluate parm as if it were a fox expr
>   FUNCTION Error(nError, cMethod, nLine)
>      COMreturnerror(cMethod+'  err#='+str(nError,5)+;
>         '  line='+str(nline,6)+' '+message(),_VFP.ServerName)
>      && this line is never executed
>ENDDEFINE
>
>
>2. And in setting up Excel to use myServer.myClass, one has to do this before running
>the macro
>
>Choose Tools, choose References, and add the myserver Type Library to the references.
>This makes it possible for the myserver Type Library information to be used in the macro.
>
>3. Here is the macro
>
>
>Sub t()
>Dim ox As New myserver.myclass  && MyServer.MyClass
>ox.mydocmd ("set exclusive off")
>ox.mydocmd ("use d:\fox70\test\customer")
>n = ox.MyEval("reccount()")
>nflds = ox.MyEval("fcount()")
>nsecs = ox.MyEval("seconds()")
>For i = 1 To n
>    For j = 1 To nflds
>        cc = "evaluate(field(" & j & "))"
>        Application.Sheets(1).Cells(i, j).Value = ox.MyEval(cc)
>    Next
>    ox.mydocmd ("skip")
>Next
>MsgBox (ox.MyEval("seconds()") - nsecs)
>End Sub
>
>
>Do you think I have to do all of these steps to be able to use the DLL
>we have been talking about?
>Thanks
>STeve


Steve,
I think you're doing something wrong. It's very easy and you don't need to add it from references (if you'd use in a macro - addins need addition but as I said before I couldn't do it with pure VFP).
Here is saomething that I just tried :
* prg that creates and builds MTDLL - first ran this
Local m.myDLL
TEXT TO m.myDLL noshow
DEFINE CLASS testclass as Session olepublic
  Datapath = "C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 7\SAMPLES\DATA"

  PROCEDURE GetCustomerAmt(tcCustomerID as String) as Currency
  LOCAL ARRAY aMaxAmt[1]
  SELECT maxordamt ;
	FROM (ADDBS(this.DataPath)+"customer") ;
	WHERE cust_id == UPPER(m.tcCustomerID) ;
	INTO ARRAY aRetVal
	return IIF(_Tally>0,aRetVal,NTOM(0))
ENDPROC

  PROCEDURE TimePlease() as Datetime
  RETURN DATETIME()
endproc
enddefine
ENDTEXT

Strtofile(m.myDLL,'opubclass.prg')

Build Project VFPopubtest From opubclass.prg

Build Mtdll VFPopubtest From VFPopubtest recompile
The I went to excel and created these 2 macros :
Sub proc1()
 Dim myVFP_COM As Object
 Set myVFP_COM = CreateObject("VFPopubtest.TestClass")
 ActiveCell.Offset(0, 1).Value = myVFP_COM.GetCustomerAmt(ActiveCell.Value)
 Set myVFP_COM = Nothing
End Sub

Sub proc2()
 Dim myVFP_COM As Object
 Set myVFP_COM = CreateObject("VFPopubtest.TestClass")
 ActiveCell.Value = myVFP_COM.TimePlease()
 Set myVFP_COM = Nothing
End Sub
Then I assigned those macros to Ctrl+K and Ctrl+L.
In a cell entered "alfki" and in another "BONAP". Keyed in Ctrl+K in those and got 6300 and 27000 in cells next to them. Keyed in Ctrl+L and got datetime and copy pasted here (03.09.2004 03:16).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform