TALtech Logo
search
Products Support Resources Free Software
   TALtech Home:  Support:  WinWedge Support:  DDE and the WinWedge: WinWedge DDE Examples:



Requesting Data from WinWedge Using a VBA Subroutine

Steps for setting up WinWedge:

1. Select "DDE Server" from WinWedge "Mode" menu. When the dialog box appears asking for a DDE Command Destination Application, enter: "EXCEL" as the Application Name and then enter: "SYSTEM" as the DDE topic.

2. Select "Input Record Structure" in the "Define" menu and define the structure of the input record(s) to WinWedge. When you get to the final Window with the caption "Input Record Definition Editor", enter the string: [RUN("GetSWData")] as the Field Postamble DDE Command after the last data field that you have defined. This is a DDE command that will be sent to EXCEL after each data record is received by the Wedge.

3. Set up the rest of WinWedge parameters and then activate it.

Steps for setting up EXCEL:

1. Create or edit a macro module and enter the following code in the module:
(To create a new module click on Insert > Module from the Menus in the Visual Basic Editor Window.)

Sub GetSWData()
Dim RowPointer As Long
 
' The following code finds the next available empty row in Column A
RowPointer = Cells(65000,1).end(xlup).row + 1

Chan = DDEInitiate("WinWedge", "Com1") ' Establish DDE link to WinWedge on Com1
' WinWedge can be configured to parse data into more than one data field. The following code demonstrates how to retrieve one or more data fields. If more than one field is specified, each field is placed in its own column.


' How many data fields are we retrieving from WinWedge?
NumFields = 1              

For X = 1 To NumFields  ' Loop through all data fields defined in the Wedge
    ' Request the data from each field in the wedge
    F1 = DDERequest(Chan, "Field(" & Format$(X) & ")")
    ' Convert the data from a variant array data type to a string    
    WedgeData$ = F1(1)       
    ' Place the data in cell location Row = RowPointer, Column = X

    Sheets("Sheet1").Cells(RowPointer, X).Value = WedgeData$
Next

DDETerminate Chan ' Close the DDE channel

' Insert a date/time stamp in the sheet in the same row as the data
Sheets( "Sheet1").Cells(RowPointer, NumFieldsCD39

03/06/19:16:44:12+1).Value = Now

End Sub

The example above sets up WinWedge to issue a DDE command consisting of the Excel "RUN" command forcing Excel to run the subroutine "GetSWData()" after each data record is received from your serial device. The "GetSWData" subroutine performs a DDERequest to WinWedge that returns the contents of FIELD(1) to a variable named "WedgeData". The data is then assigned to a cell in "Sheet1" and a pointer variable is updated so that the next input will be written to the cell directly below the last input. The example above assumes that the open workbook contains a worksheet named Sheet1.

Back to Top

TALtech Home  |  Products  |  Resources  |  Free Software  |  Support  |  Buy Now  |  Register Your Products  | 
Site Map  |  Contact TALtech  |  News