Pages

Thursday 26 June 2014

Get List Of Running MBXs

This example demonstrates how to use DDE to retrieve a topic string which contains the list of running mbx's within a mapinfo session. The function  GetMBXFromTopicString(strTopics As StringAs String  extracts the mbx name from the topic string. I have used similar code in other applications to determine if an mbx was running in the current instance of mapinfo. If it was not found, I issued a Run Application statement to fire off the mbx


Include "Mapbasic.def"

Declare Sub Main
Declare Sub
PrintListOfRunningMBXs

Declare Function GetMBXFromTopicString(strTopics As String) As String

'---------------------------------------------------------------------------------------
Sub Main
Print Chr$(12)
Set Window Message Position(1,1) Width 3 Height 5 Title "List of Running MBXs"

Call PrintListOfRunningMBXs
End Sub
'---------------------------------------------------------------------------------------
Sub PrintListOfRunningMBXs
OnError Goto CatchEx
   
   Dim nChan, i As Integer
   Dim sTopics, strMBX As String

   nChan = DDEInitiate("MapInfo", "System")
   sTopics = DDERequest$(nChan, "Topics")
   DDETerminate nChan
   strMBX = GetMBXFromTopicString(sTopics)
   i = 1
   
   Do While sTopics <> ""
      Print PathToFileName$(GetMBXFromTopicString(sTopics))
      i = i + 1
   Loop

Done:
   Exit Sub
CatchEx:
   Resume Done
End Sub
'---------------------------------------------------------------------------------------
Function GetMBXFromTopicString(strTopics As String) As String
OnError Goto CatchEx

   Dim iDelimPos As SmallInt
   strTopics = RTrim$(LTrim$(strTopics))
   iDelimPos = InStr(1, strTopics, Chr$(9))

   If iDelimPos Then
      GetMBXFromTopicString = Left$(strTopics, iDelimPos-1)
      strTopics = Right$(strTopics, Len(strTopics)-iDelimPos)
   Else
      GetMBXFromTopicString = strTopics
      strTopics = ""
   End If

Done:
   Exit Sub
CatchEx:
   Resume Done
End Function
'---------------------------------------------------------------------------------------

No comments:

Post a Comment