Book a Demo

Author Topic: Any idea why you need sub name following endsub()  (Read 4511 times)

David Rains (bioform)

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Any idea why you need sub name following endsub()
« 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!  :)


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Any idea why you need sub name following endsu
« Reply #1 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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Any idea why you need sub name following endsu
« Reply #2 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.
« Last Edit: January 19, 2011, 08:43:26 am by simonm »

David Rains (bioform)

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Re: Any idea why you need sub name following endsu
« Reply #3 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