Book a Demo

Author Topic: Debug automation VBScript  (Read 5441 times)

jongough

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Debug automation VBScript
« on: July 21, 2010, 01:29:14 pm »
I am writing some VBScripts to help populate information in the model when doing reverse engineering from an existing database. I have the script working, but has been very difficult to debug it. The error messages point to non-existent lines and give little or no information.

Is there a way to run the integrated debugger so that I can more easily build scripts and remove errors?

Thanks
   Jon

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Debug automation VBScript
« Reply #1 on: July 26, 2010, 04:20:25 pm »
Jon,

Can't you use Visual Studio to debug the scripts?

Geert

jongough

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Debug automation VBScript
« Reply #2 on: July 27, 2010, 07:33:48 am »
Geert,
   I don't have visual studio, so I cannot use that (might be able to get it if I could find a way to cause it to be invoked). However, the scripts I am using access the EA database to update attributes and therefore have to be run within EA. There is a debug option, but it only seems to be available for objects that are the subject of the database, ie application code, rather than extensions to EA.

   When traversing the EA database it would make life much easier to be able to look at variables, objects, etc to help with the construction of the scripts. The documentation on the EA database is not really adequate to make this process easy.

Regards
   Jon

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Debug automation VBScript
« Reply #3 on: July 27, 2010, 04:00:01 pm »
Jon,

If you don't have VS, there are free Express editions available for download from the Microsoft website.
I think you can even use Excel or Word (or another Office product) to run VBScript.
To run the script outside of EA you need to connect to the repository. You can also connect to currently opened repository.

There are some examples on the Sparx website that show how to connect to the currently opened repository, or you can download an example from the community website.

Geert

jongough

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Debug automation VBScript
« Reply #4 on: July 27, 2010, 05:43:16 pm »
Geert,
   I tried the Express versions, but I cannot use the latest, requires XP + SP3 and we are SP2, and the previous version, 2008, does not do VBScript. So it looks like there is no way to debug scripts that add to the EA tool unless you have an old version of Visual Studio with the requisite debugger in it.

   I am trying to work out how the scripts you pointed me to actually connect and use EA objects when there is no obvious linkage.  I may just have to continue with putting debug messages into the script and guess at where the errors are when the error messages point to completely the wrong location.

Thanks
Regards
   Jon

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Debug automation VBScript
« Reply #5 on: July 27, 2010, 06:05:23 pm »
Jon,

I think you can run VBscripts in the Word or Excel VBA editor as well.
In VBA you can connect to the current repository using:
Code: [Select]
Public Function getCurrentRepository() As EA.repository
    Dim EAapp As EA.App
    Dim EArepository As EA.repository
    Set EAapp = GetObject(, "EA.App")
    'Warning when EA not open
    If EAapp Is Nothing Then
        MsgBox "Please Open Enterprise Architect"
        'try again
        Set getCurrentRepository = Me.getCurrentRepository
    End If
    'Warning when no repository is opened.
    Set EArepository = EAapp.repository
    If EArepository Is Nothing Then
        MsgBox "Please open a Model in Enterprise Architect"
        'try again
        Set getCurrentRepository = Me.getCurrentRepository
    End If
    'return the found repository
    Set getCurrentRepository = EAapp.repository
End Function

Should not be so hard to convert this to VBScript.

Geert

jongough

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Debug automation VBScript
« Reply #6 on: July 28, 2010, 09:53:10 am »
Geert,
   I have that working now thanks, although there are some differences between the code that can be run in EA and in Excel. Its a shame that EA does not support debugging in its scripting environment.

Regards
   Jon