• 3 replies
  • Latest Post - ‏2017-05-13T09:06:19Z by ARI_SP
1 Post

Pinned topic SA crashes when deleting Definitions using VBA excel macro

‏2014-08-06T08:06:58Z | crash definitions excel macro sa vba

Hi there,

I have produced an excel macro which connects to System Architect. The excel macro deletes the defintions within system architect using the macro in excel. The macro works fine, however after I run the macro, System Architect crashes meaning that I have to close it and then start it back up again. The definitions get deleted as required but observing the code below, could anyone figure out as to why SA crashes at the end of my macro? I have tried a few different things to test it but I cant seem to figure it out.

Public Sub DeleteDefinition()
    Dim oObjects As SAObjects
    Dim imf As ISAImf
    Dim oDefinition As Definition
    Dim rowcount As Integer
    Dim lngIterationCount As Long
    Dim lngProgressPercentage As Long
    Dim intObjectCount
    Dim errorString As String
    Dim x As String
    intReplaced = 0
    Set oObjects = SA2001.Application.Encyclopedia.GetFilteredDefinitions("", DefinitionTypeNumber)
    SA2001.Application.Encyclopedia.OpenObjectsAsReadOnly = True
    SA2001.Application.Encyclopedia.OpenObjectsAsReadOnly = False
    Set imf = SA2001.Application.Interface("ISAIMF")
    frmReportProgress.lblSummary = oObjects.count & " " & DefinitionType & "s to be considered"
    lngIterationCount = 0
    intObjectCount = oObjects.count

    For Each oDefinition In oObjects
        lngIterationCount = lngIterationCount + 1
        lngProgressPercentage = ((lngIterationCount / intObjectCount) * 100)
        With frmReportProgress
            .FrameProgress.Caption = Int(lngProgressPercentage) & "%"
            .LabelProgress.Width = Int(lngProgressPercentage) * 2
        End With
'       The DoEvents statement is responsible for the form updating
        For rowcount = 2 To Worksheets("sheet1").Cells(2, 4).Value
            If = Worksheets("sheet1").Cells(rowcount, 1).Value Then
                x = imf.SADeleteDefinitionDeep(oDefinition.Handle, errorString, 10)
                intReplaced = intReplaced + 1
                Exit For
            End If
    Unload frmReportProgress
    MsgBox "Clean-up completed " & intReplaced
End Sub


Any help would be greatly appreciated,


  • jvogel-11
    51 Posts

    Re: SA crashes when deleting Definitions using VBA excel macro


    You might consider including a dictionary update, verify / repair, and/or synchronize mirror properties database routine at the end of the macro along with a routine that officially closes SA and brings it up again (optional).  SA may be confused with the removal of defintions that happened manually via the macro. The more relationships associated to a definition, the more opportunity for anomalies to occur. 

  • ambytanu123
    1 Post

    Re: SA crashes when deleting Definitions using VBA excel macro


    Whatever objects you have created,pls set them to Nothing before End Sub

  • ARI_SP
    1 Post

    Re: SA crashes when deleting Definitions using VBA excel macro


    I suggest: 

    1) Use vba code  Error handling  (OnError GOTo xx :) from where you can debug the specific object that caused a problem

    2) Use SAimf Error handling by checking value of  x after  x = imf.SADeleteDefinitionDeep(oDefinition.Handle, errorString, 10) call

      if it is not =0 then an  SAimf Error has accured, which may crash the system. If x<>0 then debug it and figure out the problem by SAimf error value