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



Sending DDE Commands to WinWedge from a VBA Subroutine

The following VBA subroutine sends a string of control codes out the serial port by issuing the DDE command "[SendOut()]" to WinWedge. This example sends an escape character (ASCII 27), a capitol "P" and a carriage return-linefeed (ASCII 13 and ASCII 10).

Sub SendEscapeP()

ChannelNumber = Application.DDEInitiate("WinWedge", "COM1")
Application.DDEExecute ChannelNumber, "[SENDOUT(27,’P’,13,10)]"
Application.DDETerminate ChannelNumber

End Sub

The following subroutine shows how to send a text string passed as an argument to the routine.

Sub SendText(StringToSend$)

ChannelNumber = Application.DDEInitiate("WinWedge", "COM2")
' The following line concatenates the SEND command with the data to be sent
Application.DDEExecute channelNumber, "[SEND(" & StringToSend$ &")]"
' The & operator is the Excel string concatenation operator thus we are concatenating
' The three strings "[SEND(" , the data in the string variable StringToSend$ and ")]"
' Thus if StringToSend$ ="ABC" then the command that is sent to WinWedge would
' be: [SEND(ABC)]"

Application.DDETerminate channelNumber

End Sub

The following subroutine sends a column of data out the serial port starting in the currently active cell. After each cell's data is sent it reads the cell directly below the current cell. If the cell contains no data then it stops otherwise it continues sending until it hits an empty cell.

Sub SendCells()

chan =DDEInitiate("WinWedge", "COM1")
MyPointer = 0

' open a link to winwedge on com1
' starting offset from current cell is 0

x$ = ActiveCell.Offset(rowOffset:= MyPointer, columnOffset:=0).Formula

While Len(x$)

' put string from current cell in variable x$
' while the length of the string is not 0

DDEExecute chan, "[SENDOUT(' " & x$ & " ',13)]"

' send the string out the port followed by a carriage return

MyPointer = MyPointer + 1

' point to the next cell down

x$ = ActiveCell.Offset(rowOffset:= MyPointer,columnOffset:=0).Formula       

 

' get next cell

Wend
DDETerminate chan

' loop until we reach an empty cell

End Sub

The following subroutine demonstrates how to send the contents of any string variable out the serial port - even strings that contain control characters or non printable ASCII characters. The string to be sent out the serial port is passed as an argument to the SendString subroutine.

Sub SendString(StringToSend$)

' The following loop reads the StringToSend$ variable and generates a string
' containing the ASCII values for each character in the string separated by commas.
' This resulting string is then used as the argument to the SENDOUT command
' below. Ex: if the variable StringToSend$ = "ABC" then the variable Arg$ will be
' "65,66,67" See the syntax of the SENDOUT command in the Wedge users manual
' for details.

For x = 1 To Len(StringToSend$)
Arg$ = Arg$ + LTrim$(Str$(Asc(Mid$(StringToSend$, x, 1))))
If x <> Len(StringToSend$) Then Arg$ = Arg$ + ","
Next

channelNumber = Application.DDEInitiate("WinWedge", "COM2")
' The following line concatenates the SENDOUT command with the data to be sent
Application.DDEExecute channelNumber, "[SENDOUT(" & Arg$ &")]"
' The & operator is the Excel string concatenation operator thus we are concatenating
' The three strings "[SENDOUT(" , the data in the string variable Arg$ and ")]"
' Thus if StringToSend$="ABC" then the command that is sent to WinWedge would
' be:[SENDOUT(65,66,67)]" - (the ASCII values for chars A, B and C are 65, 66 and
' 67)

Application.DDETerminate channelNumber

End Sub

The following subroutine demonstrates how you would call the above routine passing it the contents of a spreadsheet cell thus sending the cell contents out the serial port.

Sub TestSendString()

X$ = Sheets("Sheet1").Cells(1, 1).Value
SendString(X$)

End Sub


The following Excel VBA subroutine demonstrates how to transmit data out the serial port by "DDEPoking" to the WinWedge OutputBuffer DDE item. Sub PokeData()

chan = DDEInitiate("WinWedge", "COM2")

' open a DDE channel

DDEPoke chan, "OutputBuffer", "Hello"+Chr$(13)

' poke to the outputbuffer

' the above line pokes the word "Hello" followed by a carriage return (ASCII 13)

DDETerminate chan

' close the channel

End Sub

Back to Top

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