Topic
  • 1 reply
  • Latest Post - ‏2014-08-08T13:56:20Z by jvogel-11
therealjag
therealjag
1 Post

Pinned topic SA crashes when deleting Definitions using VBA excel macro

‏2014-08-06T08:06:58Z |

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
    oObjects.ReadAll
    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
        DoEvents
   
        For rowcount = 2 To Worksheets("sheet1").Cells(2, 4).Value
           
            If oDefinition.name = Worksheets("sheet1").Cells(rowcount, 1).Value Then
           
                x = imf.SADeleteDefinitionDeep(oDefinition.Handle, errorString, 10)
               
                intReplaced = intReplaced + 1
               
                Exit For
               
            End If
           
        Next
       
    Next
    Unload frmReportProgress
    MsgBox "Clean-up completed " & intReplaced
End Sub

 

Any help would be greatly appreciated,

Thanks,

  • jvogel-11
    jvogel-11
    51 Posts

    Re: SA crashes when deleting Definitions using VBA excel macro

    ‏2014-08-08T13:56:20Z  

    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.