Controlling Stroboscope via Automation

Stroboscope can be controlled from other applications using any programming language that supports Automation. The EZStrobe and ProbSched applications are such examples that control Stroboscope from within Visio using Visual Basic for Applications.

You can examine Stroboscope’s Automation interface by loading the Stroboscope Type Library (strbwin.tlb). In Visual Basic for Applications you can add strbwin.tlb as a reference, and then using the object explorer (typically pres F2 and then select the Stroboscope library) you can see the supported methods, arguments, and return values. Here is how the object explorer looks when opened in the VBA Window of Visio 2007:

image

Even though the “Stroboscope” type will be available in VBA as a valid type for dimensioning objects, it is best to dimension Stroboscope as a variable of type “Object”. The code below is an example that controls Stroboscope via VBA by sending a very small network, simulating it, and getting some output from it. It can be pasted as is into a Visio or Excel 2007 VBA module. To test it, execute the testStroboRun procedure:

Option Explicit
Public StroboApp As Object

'makes sure StroboApp is set to control
'Stroboscope
Public Function GetStrobo() As Object
    On Error Resume Next
    If (StroboApp Is Nothing) Then
        Set StroboApp = _
          CreateObject("Stroboscope.Document")
    End If
    If Err <> 0 Then
        MsgBox "Couldn't launch Stroboscope." _
          , vbOK + vbInformation, _
          "test Strobo"
        Err = 0
        Set GetStrobo = Nothing
    End If
    Set GetStrobo = StroboApp
End Function

'releases Stroboscope
Public Sub ReleaseStrobo()
        Set StroboApp = Nothing
End Sub

Sub testStroboRun()
    'Get the Stroboscope object,
    'if not already acquired
    GetStrobo


    Dim nResult As Integer
    On Error Resume Next
    'set name of client running Stroboscope
    StroboApp.ClientVersion "test Strobo"
    If Err <> 0 Then
        nResult = -1
        GoTo CleanUp
    End If

 
    'The following two blocks define a very
    'simple network and runs it. 
    'Any number of statements can be
    'sent in one call. It is in fact possible
    'to load an entire model from a *.str file
    'and pass it for execution as a single
    'string via the RunStatements method. 
    'If running results in an error, the line
    'number of the error will return in nResult.
    'When no errors occur nResult will be
    'assigned zero.
    nResult = StroboApp.RunStatements( _
      "GENTYPE gen;QUEUE que gen;" _
      & "COMBI DoIt;DURATION DoIt Rnd[];" _
      & "LINK l1 que DoIt;LINK l2 DoIt que;")
    If nResult <> 0 Then GoTo CleanUp


    'just some more statements that actually do
    'something: initialize, simulate and report
    'the model
    nResult = StroboApp.RunStatements( _
      "INIT que 1;SIMULATEUNTIL SimTime>=10000;" _
      & "REPORT;")
    If nResult <> 0 Then GoTo CleanUp

    'we can get information from the model
    Dim st As Double
    st = StroboApp.EvaluateExpression("SimTime")
    MsgBox "The reported simulation end time " _
      & "was: " & st

    'terminate model
    StroboApp.EndModel


CleanUp:
    If nResult <> 0 Then 
        MsgBox "STROBOSCOPE reported the " _
          & "following error: " _
          & StroboApp.geterrordescription() _
          & ".", , "test Strobo" 
    End If

End Sub