DDE Examples for Microsoft Visual Basic for Windows
Linking a VB Text Box to a WinWedge Data Field
To link a data field in WinWedge to a text box in a VB application you simply set the properties for the
text box to specify a DDE link. For example the following code would establish a "Automatic" link
between field(1) in WinWedge (active on COM2) so that whenever data changes in Field(1) of
WinWedge, it would also automatically change in the text box Text1. When a data field from
WinWedge is linked to a text box on a VB form using a "Automatic" link, the text box will also receive
a "Change" event whenever the data from WinWedge changes. If you set the LinkMode property to
"Notify", the text box will receive a "LinkNotify" event whenever WinWedge updates the data for
Field(1) - even if the data does not change. Note: If you set the LinkMode to "Notify" your
Text1_LinkNotify event handler will have to perform a "LinkRequest" method to update the textbox.
(i.e. Text1.LinkRequest)
Text1.LinkTopic = "winwedge|com2" ' set the link topic
Text1.LinkItem = "field(1)" ' set the link item
Text1.LinkMode = vbLinkAutomatic ' set the link mode to "Automatic"
Sending DDE Commands To WinWedge From A VB Application.
After a link is established between a text box and a data field in WinWedge, you could issue
commands to WinWedge using the text box "LinkExecute Method". For Example the following code
sends the string "Testing" followed by a carriage return out the serial port.
Note: WinWedge must be active on the specified serial port for the following code to work.
Text2.linkmode =vbLinkNone ' disable links before setting topic
Text2.LinkTopic = "winwedge|com2" ' set the link topic
' there is no need to set the LinkItem property when sending DDE commands
Text2.LinkMode = vbLinkNotify ' set the link mode to "Notify"
Text2.LinkExecute "[Sendout('Testing',13)]" ' send the string out the serial port
Launching WinWedge From A Visual Basic Application
Sub RunWedge()
' the shell statement passes a WinWedge config file as a command line arg.
' This causes WinWedge to automatically load the config file and activate itself.
x& = Shell("c:\winwedge\winwedge.exe c:\winwedge\ddetest.SW3")
ThreeSecsFromNow = TimeValue(Now) + TimeValue("00:00:03")
Do While TimeValue(Now) < ThreeSecsFromNow
DoEvents ' give WinWedge time to load
Loop
End Sub ' WinWedge should be loaded now
Tag : .NET
ประวัติการแก้ไข 2012-12-20 16:39:45
Date :
2012-12-20 16:38:23
By :
kung59287
View :
1584
Reply :
1
No. 1
Guest
dde เป็นโปรโตคอลโบราณที่ใช้ส่ง windows message ระหว่าง app