Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ddepoke

Status
Not open for further replies.

SBTBILL

Programmer
May 1, 2000
515
US
I'm trying to figure out how to use the DDEPOKE with Peachtree. I got DDEREQUEST going but the poke is a bit different. The code I'm using is as follows:

CLOSE DATABASE
CLEAR
SELECT 0
USE EMPLOY01 EXCL
X=DDEINITIATE("PEACHW","bcs")
? X
STORE 'START' TO Y
STORE SPACE(1) TO Y1,Y2,Y3
STORE 'FIRST' TO RECTOUSE
if x<>-1
DO WHILE .T.
? '* '+Y
Y1=dderequest(X,&quot;FILE=EMPLOYEE,&amp;RECTOUSE,FIELD=KEY&quot;)
? Y1
SELECT EMPLOY01
LOCATE FOR ALLTRIM(KEY)=ALLTRIM(Y1)
IF FOUND()
Y17=DDEREQUEST(X,&quot;FILE=EMPLOYEE,FIELD=CUSTOM5&quot;)
? Y17
=DDEPOKE(&quot;FILE=EMPLOYEE,FIELD=CUSTOM5,EMPLOY01.CUSTOM5B&quot;)
Y17=DDEREQUEST(X,&quot;FILE=EMPLOYEE,FIELD=CUSTOM5&quot;)
? Y17
? '************'
?
ENDIF
IF LEN(ALLTRIM(Y1))=0 AND RECTOUSE<>'FIRST'
EXIT
ENDIF
STORE 'NEXT' TO RECTOUSE
ENDDO
ENDIF
DDETERMINATE(X)

The message I get on the poke statement is to few arguments.

Bill Couture
 
Bill,
First, in FoxPro the DDE functions are all case sensitive, so I hope you are really using DDEInitiate( ), DDEPoke( ), etc.
Also, according to the Help topic, DDEPoke( ) requires at least 3 parameters: DDEPoke(nChannelNumber, cItemName, cDataSent [, cDataFormat [, cUDFName]]).
It's been a long time since I did any DDE code, and so I don't have any specifics for you to fix the code, but it looks like you may be using a Visual Basic example with named parameters, unfortunately FoxPro doesn't support this format - only positional parameters.

Rick

 
Interesting about the case. Will have to check. Didn't have a problem with the DDEREQUEST lines. DDETERMINATE definitly works, too.

Unfortunately the example I have are all VB. Problem seems to be with the cDataSent area. It's interesting that Peachtree doesn't even think about VFP. And VFP has almost no examples on this. Wish this was like the old days when you could just call Toledo and get an answer.

Bill Couture
 
Bill,
I found this &quot;old&quot; sample program that shows some DDE basics, I'm not sure where I got it. (Note: You'll want to fire up Excel first.)

* DDEXL.PRG
*
* This simple program shows the basic steps
* needed for FoxPro to access another application
* acting as a DDE server. To see how it works,
* single step through the code, reading the comments
* as you go. It shows the use of DDEInitiate,
* DDERequest, DDEPoke, DDETerminate and DDELastError.

****************************************************

* The first thing we have to do is start a
* conversation with the server. In this case,
* we're going to &quot;talk&quot; to Microsoft Excel.

* To do this we start or &quot;initiate&quot; the conversation
* by opening up a &quot;channel&quot; to Excel. (Note, if
* Excel doesn't start on the next step, then either
* start it manually and retry, or place it in your
* MS-DOS path before starting Windows.)

channel = DDEInitiate(&quot;Excel&quot;, &quot;Sheet1&quot;)
? &quot;Channel is:&quot;, channel

* This command will try and start Excel if it isn't
* already running and then tell it that it wants to
* talk about &quot;Sheet1&quot;. This is called the &quot;topic&quot;
* of the conversation. Every conversaction is
* about only one topic. Only certain topics are
* understood by the server and only the server
* documentation can tell you what those are. In
* the case of Excel, we are asking to talk about
* a spreadsheet called &quot;Sheet1&quot; -- the default
* empty spreadsheet that Excel opens.

* Let's ask Excel what is in cell R1C1 of the Sheet1.
* We do this with the DDERequest command, like so:

? &quot;<&quot; + DDERequest(channel, &quot;R1C1&quot;) + &quot;>&quot;

* Notice how the cell is empty. If we switch over
* to Excel and put something in the cell, we can
* try again.

? &quot;<&quot; + DDERequest(channel, &quot;R1C1&quot;) + &quot;>&quot;

* This time we get the value of the cell. Notice
* how this is returned as a string. Everything
* returned by a simple DDERequest like this will be
* a string, so if you're expecting numbers, you'll
* have to convert them into numbers explicitly.

* In the simple DDERequests above, the second
* parameter passed to the function is called the
* &quot;Item&quot;. The Item defines what this part of the
* conversation is about. Remember that we already
* know that the main topic of conversation is
* &quot;Sheet1&quot;. The Item is a sub-topic within
* the main topic.

* Another DDE command that Excel understands in a
* conversation about a spreadsheet is the &quot;Poke&quot;
* command. The DDEPoke command below tells Excel
* &quot;Here, take this value and do something with it&quot;.
* We provide an Item to help clarify exactly what
* to do with it. Thus:

? DDEPoke(channel, &quot;R1C2&quot;, &quot;2&quot;)

* will place the value 2 into cell R1C2. The &quot;R1C1&quot;
* parameter is still called the &quot;Item&quot;. The &quot;2&quot;
* parameter is called the &quot;Data&quot;. Note that it is
* string value. Just as DDERequest only returns
* strings, DDEPoke only sends strings.

* We can also 'poke' a formula into a cell, e.g.

? DDEPoke(channel, &quot;R1C3&quot;, &quot;=A1+B1&quot;)

* (Note that the Topic always uses RC notation, but
* the Data uses whatever mode Excel is currently in.)
* Switching to Excel shows that this works. In
* fact, we can now retrieve the summed cells from
* Excel using:

? &quot;<&quot; + DDERequest(channel, &quot;R1C3&quot;) + &quot;>&quot;

* When we're finished with a conversation, we can
* end it by using the &quot;DDETerminate&quot; function. I.e.

? DDETerminate(channel)

* Notice how all the DDE commands are actually
* functions. I.e., they all return a value.
* Typically this value will be .T. If an error
* occurs, then .F. will be returned. You can then
* use the DDELastError function to determine why it
* failed. For example, if I now try and Poke to
* the channel I just closed:

? DDEPoke(channel, &quot;R1C3&quot;, &quot;=A1+B1&quot;)

* I get .F. returned. By checking DDELastError

? DDELastError()

* and looking up the help entry for it, you can see
* what went wrong.

Rick
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top