Q How can I tell if an MDL application is loaded using MicroStation VBA?
Questions similar to this, posed by MDL and VBA developers, appear on the Bentley Discussion Groups, typically the VBA discussion group.
A
MicroStation VBA has no intrinsic way to find if a particular MDL application is loaded, but you can use
an MDL function mdlSystem_getTaskStatistics
. I've wrapped it in a VB function IsMdlLoaded
.
An example of its use follows …
Option Explicit' --------------------------------------------------------------------- ' modMDL shows how to tell if a named MDL application is loaded ' --------------------------------------------------------------------- ' Notice: ' ' MicroStation VBA code provided by LA Solutions at no cost and with ' no license requirement as part of the MDL example project ' ' This software is provided with no warranty and no declaration of ' fitness for any purpose. No support is provided. ' You may use this software and copy it to others inside or outside ' your organisation provided that this notice is retained in full. ' ' LA Solutions Ltd ' www.la-solutions.co.uk ' ' End of notice ' --------------------------------------------------------------------- ' MDL Function Prototypes ' The #If condition statement is a Microsoft VBA 7.1 compiler directive. ' ---------------------------------------------------------------------
#If VBA7 Then ' Declaration for 64-bit MicroStation Declare PtrSafe Function mdlSystem_getTaskStatistics Lib "ustation.dll" ( _ ByVal statisticsP As LongPtr, _ ByVal taskIdP As LongPtr) As Long #Else ' Declaration for 32-bit MicroStation Declare Function mdlSystem_getTaskStatistics Lib "stdmdlbltin.dll" ( _ ByVal statisticsP As Long, _ ByVal taskIdP As String) As Long #End If' ---------------------------------------------------------------------
Sub Main() Dim mdlapp As String mdlapp = "IGEN" If (IsMdlLoaded(UCase (mdlapp))) Then Debug.Print "'" & mdlapp & "' is loaded" Else Debug.Print "'" & mdlapp & "' is not loaded" End If End Sub' ---------------------------------------------------------------------
Public Function IsMdlLoaded(ByVal appName As String) As Boolean IsMdlLoaded = False On Error GoTo err_IsMdlLoaded Const SUCCESS As Long = 0 If (SUCCESS = mdlSystem_getTaskStatistics(0, StrPtr(appName))) Then IsMdlLoaded = True End If Exit Function err_IsMdlLoaded: MsgBox "Error no. " & CStr(Err.Number) & ": " & Err.Description, vbCritical Or vbOKOnly, "IsMdlLoaded Error" End Function