• 1 reply
  • Latest Post - ‏2010-12-06T20:51:31Z by EdwardOverton
10 Posts

Pinned topic Checking if a Package or Requirement Exists before Creation

‏2009-12-16T19:32:47Z |

I am creating a ton of packages and a ton of requirements, even a bunch of views in my VB code. How can I check if these packages already exist, with the same name of course. Right now I'm going through creating all the packages, but if one of those packages already exists, like the first one for example, it throws an error. Would it be best to just have it skip the error and move on? If so, could you show a good way to do that.

Thank you!
Andrew Davis
Updated on 2010-12-06T20:51:31Z at 2010-12-06T20:51:31Z by EdwardOverton
  • EdwardOverton
    3 Posts

    Re: Checking if a Package or Requirement Exists before Creation

    ‘ The follow code is a snippet of code you must connect to and open the project
    ‘ After this code you should close the project
    Dim aProject As ReqPro40.Project
    Dim aReqs As ReqPro40.Requirements
    Dim aReqType As ReqPro40.ReqType
    Dim aTag as String

    ' Attempt to retrieve requirement type of tag=aTag
    ' BR = Business Rules
    aTag = "BR"
    Set aReqs = aProject.GetRequirements(aTag, _
    If aReqs Is Nothing Then
    ' requirement type does not exist
    Set aReqType = aProject.ReqTypes.Add("sName", _
    aTag, _
    eReqStyles_DoubleUnderline, _
    eReqColors_Blue, _
    1, _
    "Description", _
    "", _
    If Not aReqType Is Nothing Then
    End If
    MsgBox "Requirement " & aTag & " already exists!"
    End If

    ' The bolded code can be replaced with
    aReqType.Attrs.Add and the appropriate arg values - add attributes
    ReqAttr.ListItems.Add and the appropriate arg values - add list of values
    ' See if a package exists, you have to know its key
    Set aPackage = aProject.GetPackage(PackageKey, _

    Hope this helps