Book a Demo

Author Topic: Finding Packages by name in VBA  (Read 4102 times)

elgringogordo

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Finding Packages by name in VBA
« on: October 23, 2018, 09:21:00 pm »
Hi I am trying to automate using an excel sheet to create and update an EA requirements list.

It's quite basic.  I add one top level package.  I want to iterate some cells, check if the package exists and add it if it doesn't.  (Afterwards I add a hierarchy of elements, this 2nd part is mainly done).  So I think the main point is I manually add a root package and then want to add a single layer of packages afterwards.

I'm struggling to check the existence of packages though.  Here is a snippit of code (currently I have added the packages to EA manually and I'm starting off by checking the sheet against ea.

    dim myP as EA.Package

    For Each packageString In packageArray
        MsgBox (CStr(rootPackage.Packages.Count))  ' shows 35
        Set myP = rootPackage.Packages.GetByName(packageString ) 

So this set should be fine, in this case it should exist but what I get is a runtime error : Index out of Bounds

Can anyone tell me what I'm doing wrong ?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding Packages by name in VBA
« Reply #1 on: October 23, 2018, 09:35:18 pm »
You shouldn't use GetByName (ever)

Why don't you simply loop the packages until you have the one you need?

Something like:

Code: [Select]
    dim myP as EA.Package
    dim curP as EA.Package
    set curP = nothing 'initialize

    For Each packageString In packageArray
        For Each curP in rootPackage.Packages
            If curP.Name = packageString then
                 Set myP = curP
                 exit for
            end if
        next
   next

Geert
« Last Edit: October 23, 2018, 10:04:47 pm by Geert Bellekens »

elgringogordo

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Finding Packages by name in VBA
« Reply #2 on: October 23, 2018, 09:50:17 pm »
Many thanks