Download WINWEDGE USERS MANUAL
Transcript
DDE Examples for Microsoft Word for Windows
Steps For Setting Up WinWedge:
1. Select “DDE Server” from the “Mode” menu in WinWedge. When the dialog box appears
asking for a Target Application DDE Command, enter: WinWord as the DDE Application
Name and for the DDE topic enter the string: System. For the DDE Command, enter the
string: [GrabData()]. This is a DDE command that will be sent to Word after each data record
is received by WinWedge.
2. Set up the rest of the WinWedge parameters as required for your serial device and
activate it.
Steps For Setting Up Word:
When you create a WordBasic macro or subroutine in Word and save it in the Global macro
sheet, the name of the subroutine automatically becomes a valid Word DDE command.
Create a new macro by selecting "Macro" from the TOOLS menu. When the dialog box
appears prompting for a macro name, enter the name: GRABDATA and then click the button
labeled "Create". Enter the following code in the macro editor window:
Sub GrabData()
chan = DDEInitiate("WinWedge", "COM1")
MyData$ = DDERequest$(chan, "Field(1)")
DDETerminate chan
Selection.TypeText Text:= MyData$
Selection.TypeParagraph
return)
End Sub
' open a link to WinWedge
' get the data from WinWedge
' close the link
' enter the data into the open document
' insert a paragraph marker (hard
After you are done entering the code select "Close" from the FILE menu to save the macro.
This example sets up WinWedge to issue a DDE command ([GRABDATA()]) to Word after
each data record is received from your serial device. This causes the GRABDATA subroutine
to run which then performs a DDERequest back to WinWedge asking for the data in Field(1)
in WinWedge Window. This data is returned to Word in the variable: MyData$. Once the data
from WinWedge is in a variable, you can do whatever you like with it by including additional
code of your own design. This example simply inserts the text in the MyData$ string variable
into the open document and then inserts a paragraph marker to move the cursor to the next
line down.
The following code fragment shows how to transmit a string out the serial port from Word:
' open a link to WinWedge
' transmit "Test" and a carriage return
' close the link
Chan = DDEInitiate("WinWedge", "COM2")
DDEExecute Chan, "[Sendout('Test',13)]"
DDETerminate Chan
92