home *** CD-ROM | disk | FTP | other *** search
- * DDEXL1.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 "talk" to Microsoft Excel.
-
- * To do this we start or "initiate" the conversation
- * by opening up a "channel" 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("Excel", "Sheet1")
- ? "Channel is:", channel
-
- * This command will try and start Excel if it isn't
- * already running and then tell it that it wants to
- * talk about "Sheet1". This is called the "topic"
- * 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 "Sheet1" -- 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:
-
- ? "<" + DDERequest(channel, "R1C1") + ">"
-
- * Notice how the cell is empty. If we switch over
- * to Excel and put something in the cell, we can
- * try again.
-
- ? "<" + DDERequest(channel, "R1C1") + ">"
-
- * 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
- * "Item". The Item defines what this part of the
- * conversation is about. Remember that we already
- * know that the main topic of conversation is
- * "Sheet1". The Item is a sub-topic within
- * the main topic.
-
- * Another DDE command that Excel understands in a
- * conversation about a spreadsheet is the "Poke"
- * command. The DDEPoke command below tells Excel
- * "Here, take this value and do something with it".
- * We provide an Item to help clarify exactly what
- * to do with it. Thus:
-
- ? DDEPoke(channel, "R1C2", "2")
-
- * will place the value 2 into cell R1C2. The "R1C1"
- * parameter is still called the "Item". The "2"
- * parameter is called the "Data". 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, "R1C3", "=A1+B1")
-
- * (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:
-
- ? "<" + DDERequest(channel, "R1C3") + ">"
-
- * When we're finished with a conversation, we can
- * end it by using the "DDETerminate" 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, "R1C3", "=A1+B1")
-
- * I get .F. returned. By checking DDELastError
-
- ? DDELastError()
-
- * and looking up the help entry for it, you can see
- * what went wrong.