Hi All,
I have a design question about VB.Net programming. I've read two books on VB.Net programming and they all seem to share a common premise:
All your buiness logic code is in the same file as your form code and it all starts when your form is loaded: ie: everything starts with Form.Load(). And lots of wizards get used to create everything automajically.
OK, thats great for small programs and examples but what if I wanted to do it differently? What if I wanted my program to start at sub Main() in a file thats just for business logic? What if I wanted to write all my own SQL command strings because I'm using DB generated autoincriment values? (OK, I used to be a C/C++ programmer). With that thinking, all the "large" objects for an app that talk to a database would be global vars in that file, sub Main() would initialize them all, do all the initial setup, getting data from the DB, population of controls with data, etc.
What do I want to do that? Because I have multiple forms and I want all the logic that isnt form specific to be in one place where I can see it all.
Anyway, after all that stuff gets done sub Main() would call application.Run() and then forms get loaded, mouse clicks work, and the whole program is now serviced by event handlers that call subs from the business logic file.
I've run into a problem with this approach already, albit minor:
I had to set the .SelectedIndex property of a ListBox control but darn it I couldnt set it in sub Main(). Code would compile and run but have no effect. I finally tried setting it in form.Load() for the form that control belonged to and suddenly it just worked. Strange.
So my question is: Is my approach something that is known to work or am I way off base?
And: Has anyone else seen unusual behavior like this? One would think that you could manipulate controls any way you like from sub Main() but clearly, you cannot. What about being able to manipulate other objects like DataSets and Currency managers?
Thanks in advance!
-John C.
Start Free Trial