What is DDE and why use it you say? Well using DDE with Netscape is much like using sendkeys, except that sendkeys does not always work with Netscape and DDE cannot be easily interupted and is much less complex. Well now that we know this, let's get to the source code and project.
First off, open a new project and create one command button and one textbox. The text box should be set as invisible and make sure that the name of it (not text) is called "txtdde". This name is very important in the program. Next go to the source code for the command button and type in the following
'URLofsite can be any url such as http://www.yahoo.com do not forget the quotes around the url.
Dim well%
well% = DDEComm%("WWW_Activate")
If well% = 1 Then
well% = DDEComm%("URLofsite")
End If
Next, create a new function called DDEComm% and go to its source code box.
Public Function DDEComm%(operation$)
'WindowID$ will be the Netscape window you address. Execute the
'the function will return 1 if successful, 0 otherwise
'for Operation$, set it to either "WWW_Activate" to activate a
'window, or a URL
'for more info on DDE implementation go to http://home.netscape.com/newsref/std/ddeapi.html
'WWW_Activate call first to get a WindowID
Static WindowID$
'error trap
On Error GoTo ErrorHandler
'turning off DDE links, just in case. You will need a hidden text
'box control named txtDDE
txtdde.LinkMode = 0
Select Case operation$
txtdde.LinkMode = 0
Case "WWW_Activate"
txtdde.LinkTopic = "Netscape|WWW_Activate"
txtdde.LinkItem = "-1,0"
txtdde.LinkMode = 2
txtdde.LinkRequest
If Len(txtdde.Text) > 0 Then
WindowID$ = LTrim$(Str$(Asc(Left$(txtdde.Text, 1))))
DDEComm% = 1
Else
DDEComm% = 0
End If
If WindowID$ = "" Or WindowID$ = Chr$(0) Then DDEComm% = 0 Else
DDEComm% = 1
Case Else
txtdde.LinkTopic = "Netscape|WWW_OpenURL"
txtdde.LinkItem = operation$ + ",," + WindowID$ + ",7"
txtdde.LinkMode = 0
txtdde.LinkMode = 2
txtdde.LinkRequest
End Select
Exit Function
'Here's the error trap. Sometimes you get errors simply because
'Netscape couldn't connect in time or whatever. Point is, repeat the
'call, and it will work the second time, unless there is a real problem.
ErrorHandler:
'put whatever error-handling stuff you want here
DDEComm% = 0
End Function
If you want to learn more about Netscape DDE, visit Netscapes DDE page
Well, that's it for this tutorial. If you want to see more information or have a correction or addition, please e-mail me.
If you would like to make a tutorial, please e-mail me.
