Author Topic: Sample Code not working!! Please help  (Read 4564 times)

Gerhard

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Sample Code not working!! Please help
« on: March 21, 2005, 12:04:07 pm »
Hi, I have the following code in a macro in WORD:


Sub CleanConstraints()
'
' CleanConstraints Macro
' Macro created 21-03-2005
'
   Dim App As Object
   
   Dim counter As Integer
   Dim i As Integer
   Dim J As Integer
   Dim k As Integer
   Dim MyModel As Object
   Dim MyPackage As Object
   Dim MyElement As Object
       
   Set App = CreateObject("EA.APP")
   App.Repository.OpenFile ("teste.EAP")
   
   For counter = 0 To App.Repository.Models.Count - 1
      Set MyModel = App.Repository.Models.GetAt(counter)
      For i = 0 To MyModel.Packages.Count - 1
     
         Set MyPackage = MyModel.Packages.GetAt(i)
         For J = 0 To MyPackage.Elements.Count - 1
             Set MyElement = MyPackage.Elements.GetAt(J)
             
             If MyElement.Stereotype = "table" Then
                 Set ob = MyElement.Constraints.AddNew("Appended", "Type")
                 ob.Update
                 For k = 0 To MyElement.Constraints.Count - 1
                   Set ob = MyElement.Constraints(k)
                   If ob.Name = "Appended" Then
                      MyElement.Constraints.DeleteAt k, False
                   End If
                Next
             End If
         Next
      Next
   Next
   App.Repository.CloseFile
End Sub


When it reaches Constraints.deleteAt it gives an Internal Application Error.

This also happens in Delphi, with the same code

I did not test it with VB, only Delphi and VBA. I guess there is some problem with the automation collection's ?

I'm using the latest trial version

can somebody test this? or give an hint?

Thanks a lot
Regards
« Last Edit: March 21, 2005, 12:05:12 pm by Gerhard »

thomaskilian

  • Guest
Re: Sample Code not working!! Please help
« Reply #1 on: March 23, 2005, 03:51:40 am »
It doesn't work here either. I once had an issue related to collections.
Quote
> The method GetByName does not return a result on
> Repository.Issues The same applies to .Tasks (and others?)

You're right, only Models, Packages, Elements and Diagrams collections
support the GetByName method, all other collections should return
"Action not supported."

In these cases it is necessary to iterate though the collection testing
the name value explicitly.


Maybe the DeleteAt is not implemented correctly?

Tjerk

  • EA User
  • **
  • Posts: 231
  • Karma: +1/-0
    • View Profile
Re: Sample Code not working!! Please help
« Reply #2 on: March 23, 2005, 08:05:09 am »
I'm not really into VB, but the collection handling isn't really correct. Once you delete one item from the collection, the 'k' index that you use already points to the next item. You might at least consider decreasing k with one when a delete has been issued. And I'm not sure if the "MyElement.Constraints.Count - 1" is evaluated once (at the start) or every time the loop starts. If it's the first case and you delete one item, your index 'k' runs higher than the collection size.

Gerhard

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Sample Code not working!! Please help
« Reply #3 on: March 23, 2005, 10:54:02 am »
Quote
I'm not really into VB, but the collection handling isn't really correct. Once you delete one item from the collection, the 'k' index that you use already points to the next item. You might at least consider decreasing k with one when a delete has been issued. And I'm not sure if the "MyElement.Constraints.Count - 1" is evaluated once (at the start) or every time the loop starts. If it's the first case and you delete one item, your index 'k' runs higher than the collection size.


Hi,

I See your point, but that part was taken from the sample code on the default EA instalation.

However I have thought of that. If instead of the loop I simply put "DeleteAt 0, False" (knowing it exists constraints) it gives the same error! So It's not due to the index loop :(

thanks for your reply
Regards

Gerhard

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Sample Code not working!! Please help
« Reply #4 on: March 23, 2005, 10:58:32 am »
Quote
It doesn't work here either. I once had an issue related to collections.

Maybe the DeleteAt is not implemented correctly?


Hi,

Maybe, Im not sure, however my code is based on the sample code EA installs : \Code Samples\VB_Sample\VB_Sample.frm

So it should work ???

Thanks
Regards



thomaskilian

  • Guest
Re: Sample Code not working!! Please help
« Reply #5 on: March 24, 2005, 01:25:03 am »
The code is absolutely correct. The DeleteAt has the False parameter to indicate that the index is not to be changed. Only after invoking refresh, the index should be renumbered. So I think this is a bug and should be reported to Sparx.
« Last Edit: March 24, 2005, 01:25:28 am by thomaskilian »

Gerhard

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Sample Code not working!! Please help
« Reply #6 on: March 24, 2005, 08:37:01 am »
Quote
The code is absolutely correct. The DeleteAt has the False parameter to indicate that the index is not to be changed. Only after invoking refresh, the index should be renumbered. So I think this is a bug and should be reported to Sparx.


Hi, Thanks for your reply.

What is the procedure to report bugs to the author?

Thanks
Regards

thomaskilian

  • Guest
Re: Sample Code not working!! Please help
« Reply #7 on: March 29, 2005, 02:10:13 am »