Book a Demo

Author Topic: Need Help: VBScript - Object value not set  (Read 5318 times)

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Need Help: VBScript - Object value not set
« on: November 11, 2016, 09:06:51 pm »
I have written this code. And on line 38 it says "Object value not set". Can anyone see what I have done wrong? What I am trying to do is find a Package in the repository and add subpackages and elements. Anyone want to share a script for that?

sub main
'on error resume next
    dim applicationsPackage as EA.Package
   dim repositoryRoot as EA.Package
   dim i
   dim currentModel as EA.Package
   dim newApplicationName
   dim newApplicationsPackage as EA.Package
   
   Repository.EnsureOutputVisible "Script"
   
   Session.Output("Starting.")
   
   newApplicationName = InputBox("Application Name:")   
   set repositoryRoot = Repository.Models.GetByName("NAV_Virksomhetsarkitektur")
   
   set applicationsPackage = Repository.GetPackageByGuid("{4AF22AE4-A589-4ba3-9BD6-1BA7B1E99D55}")
   for i = 0 to applicationsPackage.Packages.Count - 1
      set newApplicationsPackage = applicationsPackage.Packages.GetAt( i )
      Session.Output(i & " '" & newApplicationsPackage.Name  & "'")
   next
   
   dim applicationPackage as EA.Package
   applicationPackage = GetPackageByName(applicationsPackage, newApplicationName)
   
   if applicationPackage = Nothing then
      Session.Output("    Adding new application : '" & newApplicationName & "'")
   else
      Session.Output("    Updating existing application : '" & newApplicationName  & "'")
   end if

   Session.Output("Done.")
end sub

function GetPackageByName(packagesToSearch, packageName)
   on error resume next
   dim package as EA.Package = Nothing
   
   set package = packagesToSearch.GetByName(packageName)
   
   GetPackageByName = package
end function

main

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Need Help: VBScript - Object value not set
« Reply #1 on: November 11, 2016, 09:33:14 pm »
Change it to

if applicationPackage is Nothing then

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Need Help: VBScript - Object value not set
« Reply #2 on: November 12, 2016, 04:08:54 am »
Change it to

if applicationPackage is Nothing then

q.
Indeed, that will solve the problem.

PS. I never use the EA.Collection.GetByName as it doesn't work on every collection, and I'm never sure what it does when there are two elements in the collection with the same name.