start method in class

New to Gambas? Post your questions here. No question is too silly or too simple.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

Why does your class HAVE to be the startup ?
Can you not just make a Startup.module then have it load the class?
' Gambas module file

Public Sub Main()
  
  Class.Load("MyStartingClass")
  
End
Or...
' Gambas module file

Public Sub Main()
  
  MyStartingClass.Run
  
End
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

It's kinda badly named isn't it ?

Setting the "Startup class"
(but sorry you can't use a class just a module ! lol)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

Benoit provided the simple answer on the mailing list (bless him)...

Main() must be static

Static Public Sub Main()

End
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: start method in class

Post by vuott »

BruceSteers wrote: Monday 11th July 2022 11:48am Benoit provided the simple answer on the mailing list......
ok :!:
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

I'm guessing the whole class should then have to be static too?
and any global variables referenced from Main() would need to be declared as static too.
' Gambas class file

Create Static 

Static $myGlobalInteger As Integer

Static Public Sub Main()

$myGlobalInteger = 5

End

But i could well be wrong about that.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: start method in class

Post by thatbruce »

BruceSteers wrote: Monday 11th July 2022 3:01pm I'm guessing the whole class should then have to be static too?
and any global variables referenced from Main() would need to be declared as static too.
' Gambas class file

Create Static 

Static $myGlobalInteger As Integer

Static Public Sub Main()

$myGlobalInteger = 5

End

But i could well be wrong about that.
Perhaps ;) Reread the first bit of the Create Static help till yours eyes bleed (and then tell me what it means :( )
I have only ever had one case where I had to use that command. Don't ask, I have no idea why.
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: start method in class

Post by thatbruce »

BruceSteers wrote: Monday 11th July 2022 3:07pm It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.
do much other than everything that you need done before your real main processing begins....
Is the internet up?
Is the database server running?
Is it Friday the 13th?

etc
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply