Book a Demo

Author Topic: VB Script Error  (Read 7147 times)

RobM

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
VB Script Error
« on: July 02, 2013, 02:54:02 pm »
Hello,

I have the following vbScript (unfinished):



option explicit

sub Main()

      Repository.EnsureOutputVisible("Script")
      Repository.ClearOutput("Script")

      dim common as EA.Package
      set common = Repository.GetPackageByID(382)
      dim integration as EA.Package
      set integration      = Repository.GetPackageByID(380)
      dim temporal as EA.Package
      set temporal = Repository.GetPackageByID(383)

      for each Element in common
            if Element.Stereotype = "table" then
                  Session.Output (common.Name & " --> " & Element.Name)
            end if
      next

end Sub

Main




It errors with:

script name error: Internal application error., Line 8


I cannot for the life of me figure out what is wrong with the dim statement or anything else around it....

Can someone please help me out here?

Thanks in advance

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: VB Script Error
« Reply #1 on: July 02, 2013, 03:20:33 pm »
My guess: packages have a dual personality and consist of a package object (from the t_package table) and an element object (from the t_object table), and you have used the t_object.Object_ID to try to read the package object. Use the t_package.Package_ID instead.

HTH
« Last Edit: July 02, 2013, 03:21:34 pm by KP »
The Sparx Team
[email protected]

RobM

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: VB Script Error
« Reply #2 on: July 02, 2013, 04:03:55 pm »
I don't think so because the script itself is falling over on the 'dim' statement.

The problems is...I have had various versions of this script run and then all of a sudden I'll make a seemingly unrelated change and get this Internal Application error and nothing will fix it other than deleting the script and starting over again.

It's like the vbscript engine has issues.

As a first step question...Can you see anything wrong or incorrect with the 'dim' statement? Do I actually need to declare the type as EA.Package?  I have seen other script examples where they have just declared the variable name without the type...

Cheers

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VB Script Error
« Reply #3 on: July 02, 2013, 04:13:37 pm »
Rob,

IIRC these scripting languages don't really use strong typing (since they they are interpreted and not compiled), so you should be able to leave the EA.Package off.

Maybe that helps?

Geert

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: VB Script Error
« Reply #4 on: July 02, 2013, 04:25:08 pm »
Hi Rob, I did actually try running your script before replying, and when I put an object ID in the GetPackageByID() it gave me exactly the same error message as you, on the GetPackageByID() command, but with a package ID it worked fine.

Go Edit > Find in Project, click the "Builder" button, open the SQL tab and run this search:

Code: [Select]
SELECT t_object.Name, t_object.Object_ID, t_package.Package_ID
FROM t_object, t_package
WHERE t_object.Object_Type='Package'
AND t_object.ea_guid=t_package.ea_guid

That should give you an idea of what numbers you need to put in the GetPackageByID() commands.

HTH
« Last Edit: July 02, 2013, 04:26:27 pm by KP »
The Sparx Team
[email protected]

RobM

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: VB Script Error
« Reply #5 on: July 03, 2013, 12:17:23 pm »
Thanks Guys...

Geert > Thanks for the tip...however...declaring types does not appear to hurt and it helps when relying on Intellisense.

KP > Thanks for the explanation. I'm still a bit unclear on the Object vs Package concept but with your assistance I have rewritten the script as below and am getting a sensible result (after running the SQL query and getting Package Ids).



option explicit

sub main()

      Repository.EnsureOutputVisible("Script")
      Repository.ClearOutput("Script")

      dim idx
      dim cmn      as EA.Package
      dim int      as EA.Package
      dim tmp      as EA.Package
      dim elm      as EA.Element

      set cmn = Repository.GetPackageByID(82)
      set int      = Repository.GetPackageByID(80)
      set tmp = Repository.GetPackageByID(83)

      Session.Output (cmn.Name)

      for idx = 0 to cmn.Elements.Count - 1
            set elm = cmn.Elements(idx)
            if elm.Stereotype = "table" then
                  Session.Output (cmn.Name & " --> " & elm.Name)
            end if
      next

end Sub

main



Still don't understand why 'for...each' doesn't work but happy enough to go with indexed for next instead....

Thanks again for you help.

Much appreciated....

Regards
Rob M

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VB Script Error
« Reply #6 on: July 03, 2013, 04:38:33 pm »
The foreach doesn't work because you forgot to indicate the collection to iterate.

You probably should have used:
Code: [Select]
dim element as EA.Element
for each element in common.[highlight]Elements[/highlight]
' do stuff
next

Geert

RobM

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: VB Script Error
« Reply #7 on: July 04, 2013, 04:12:15 pm »
Hi Geert,

Thanks for the advice (I should have spottted that myself!).

I've got the whole script working now with all the bells and whistles, so thankyou again for your help.

Cheers
Rob M