Not really forms, but witout forms. A question about Shared

Denaes

Senior Contributor
Joined
Jun 10, 2003
Messages
956
Formless Application:

Ok, you need a sub Main. I read elsewhere that your Main needs to be Shared like so:

Visual Basic:
Shared Sub Main

Now I want to declare my variables, which I normally do on the class level, not inside of a sub procedure, unless they're going to be used only in a single procedure. This got me errors.

I have another sub for reading data (ini type settings) from a XML file and transferring everything to a variable. This sub also had to be Shared to get it to work.

Also since both the Sub Main and Sub XMLRead were both shared, variables on the Class level wouldn't work with each other.

I even tried making the variables public on the Class level, and it was a no go. So I made a Module and made the variables public in there, and that worked.

Is all of this common to formless programming or am I missing some key elements. Its working, but I'd prefer to do things the more proper way instead of just "patchworking" it. f

I'm assuming its doing this because there isn't a Form to tie the subs together.

If theres a better or more proper way to do this sort of thing I'd really like to know :)
 
Developers like better to declare things as shared then in a module...

There's a bunch of things, as a developer, I don't care... and one of those things are exactly that shared declaration method. Is has several good uses but somethings give us much less head ache.

So, when I have to do something like yours I use Modules... I declare the Sub Main as Public, all variables are declared on the module and everything works great...
Your classes must be declared inside the module too...

I really don't see any inconvinience on using Modules rather than Shared Classes...
 
oh, ok. I guess you can declare shared variables then...

I think the module is easier. well for me its slightly annoying because I forgot like 5 xml fields, which ment I needed to add 5 more variables and 5 more lines of XMLRead code.

Of course I realized it one at a time, so thats like 10 cycles through the xml, main and module :p
 
Back
Top