home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "Module1"
- '*************************************************************
- ' DDE.BAS: An application independant, reusable module that
- ' peforms DDEExecute and DDERequest methods.
- '*************************************************************
- '*************************************************************
- ' Require variable declartion, make text comparisions case-
- ' insensitive, and declare API functions.
- '*************************************************************
- Option Explicit
- Option Compare Text
- '#If Win16 Then
- Private Declare Function GetModuleHandle Lib "Kernel" _
- (ByVal ModuleName As String) As Integer
- '#End If
- '*************************************************************
- ' Execute one DDE Command.
- '*************************************************************
- Public Sub DDEExecute(Source As Control, DDEApplication$, _
- DDECommand$, Optional DDETopic)
-
- On Error GoTo DDEExecute_Error
- '*********************************************************
- ' If the program isn't running, then exit.
- '*********************************************************
- If GetModuleHandle(DDEApplication) = 0 Then
- MsgBox "This feature requires " & _
- UCase$(DDEApplication) & _
- ".EXE to be running!", vbCritical
- Exit Sub
- End If
- '*********************************************************
- ' If the optional argument wasn't provided, then assume
- ' System.
- '*********************************************************
- If IsMissing(DDETopic) Then DDETopic = "System"
- '*********************************************************
- ' Manual connect, execute the command, and close the link.
- '*********************************************************
- Source.LinkTopic = DDEApplication & "|" & DDETopic
- Source.LinkMode = 2 'Open the Link
- Source.LinkExecute DDECommand 'Send the Command
- Source.LinkMode 0 'Close the Link
- Exit Sub
-
- DDEExecute_Error:
- Resume Next
- End Sub
- '*************************************************************
- ' Execute a DDE Command.
- '*************************************************************
- Public Sub DDERequest(Source As Control, DDEApplication$, _
- DDETopic$, DDEItem$)
-
- On Error GoTo DDERequest_Error
- '*********************************************************
- ' If the program isn't running, then exit.
- '*********************************************************
- If GetModuleHandle(DDEApplication) = 0 Then
- MsgBox "This feature requires " & _
- UCase$(DDEApplication) & _
- ".EXE to be running!", vbCritical
- Exit Sub
- End If
- '*********************************************************
- ' Manual connect, request the data, and close the link.
- '*********************************************************
- Source.LinkTopic = DDEApplication & "|" & DDETopic
- Source.LinkItem = DDEItem
- Source.LinkMode = 2
- Source.LinkRequest
- Source.LinkMode = 0
- '*********************************************************
- ' WARNING: If you wish to use a topic such as NextRow,
- ' you will have to rewrite this program so that
- ' the link is not broken. NextRow and PrevRow
- ' require a consistant link in order to cycle
- ' through the database.
- '*********************************************************
- Exit Sub
-
- DDERequest_Error:
- Resume Next
- End Sub
- '*************************************************************
- ' Locate a string within Source, and replace it with
- ' ReplaceStr.
- '*************************************************************
- Public Function Replace(ByVal Source$, FindStr$, _
- ByVal ReplaceStr$) As String
- Dim res%, retStr$
- '*********************************************************
- ' See if the search string exists.
- '*********************************************************
- res = InStr(Source, FindStr)
- '*********************************************************
- ' While FileStr is in Source, continue to replace it with
- ' ReplaceStr.
- '*********************************************************
- Do While res <> 0
- retStr = retStr & Left$(Source, res - 1) & ReplaceStr
- Source = Mid(Source, res + 1)
- res = InStr(Source, FindStr)
- Loop
- '*********************************************************
- ' Don't forget to return whatever is left over in source.
- '*********************************************************
- Replace = retStr & Source
- End Function
-