Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: David Rains (bioform) on January 18, 2011, 05:14:09 pm

Title: Any idea why you need sub name following endsub()
Post by: David Rains (bioform) on January 18, 2011, 05:14:09 pm
This works....
=========
option explicit

sub main()
      if True then
            msgbox("True")
      else
            msgbox("False")
      end if
end sub
main
=========

This does not - no error, code is not running, just nothing...
....................
option explicit

sub main()
      if True then
            msgbox("True")
      else
            msgbox("False")
      end if
end sub
....................

I see in the examples NOW that this is present, but no mention in my VBScript book or within EA help? Did I just miss something?

I am running Windows 7 (64) and EA 7.5 Build 848

Man HAVE I wasted sometime over this!  :)

Title: Re: Any idea why you need sub name following endsu
Post by: Geert Bellekens on January 18, 2011, 05:55:38 pm
David,

I can't seem to find any reference about this in the manual either, but I've seen that all the examples do have the name of the "main" sub as last statement.

If you send a bug report I'm sure Sparx will update the manual.

Geert
Title: Re: Any idea why you need sub name following endsu
Post by: Eve on January 19, 2011, 08:37:02 am
The word main at the end of the first example is calling the function defined.  Without it the script just defines a function then finishes.

The function isn't called automatically just because it's called main.

My personal preference when scripting is to just write my 'main' code directly at the file level instead of defining a function and calling it.
Title: Re: Any idea why you need sub name following endsu
Post by: David Rains (bioform) on January 19, 2011, 08:55:02 am
doink!  :)

It's funny really because my first cut on my script was jsut that... and it worked fine (proof-of-concept) it was only we I started refactoring my code things when wacky!

Okay thanks for clearing that up... It was kinda obvious ONCE you mentioned it!

David "I shoulda had a C#" Rains