Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub Main() 1

Status
Not open for further replies.

LonnieJohnson

Programmer
Joined
Apr 16, 2001
Messages
2,628
Location
US
I am new to .Net. Most of my VB is actually VBA. However, I was playing around with a simple form and command button to say "Hello".

I was prompted for the procedure Sub Main() when I tried to build the project. I found a thread somewhere that said to put it in any module. I did it and it works.

I want to know what this proc is for and where do I really put it?

Thanks.

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
Technically, yes you can put it anywhere. However it's best to have a startup class or startup module with Sub Main() - much better than sticking a Sub Main randomly in a class dedicated to specific logic.
 
Thanks. So this module gets ran first whenever the program runs? Hmmmm

Thanks...

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
In a windows project you can choose what runs first.
Sub Main, Form1, Form2 etc.

You go to Project/Properties and choose what you would like in the start up dropdown.

If you need a sub main example let me know

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
Thank you .NetDoc,

Yes, I would like to see an example. My programming skills only encompass MS Access, VBA and SQL Server.

A I am working for is small and has acquired .Net but cannot send me to classes yet. Most of their stuff is in Access. What do you suppose I do to get acclimated?

Thanks again,,,


ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
To add a Module to your project you need to go to
Project/Add Module.

I call mine Startup.

Module Startup

'I declare all of my forms in the module.
'Everything in a module is inherantly shared
' So you will have access to your forms from anywhere
'in your project
Friend MainForm As New MainForm()
Friend myCheckForm As New frmCheckBook
Friend myQue As New Queue

Sub Main()
'In sub main I show my startup form
MainForm.ShowDialog()
End Sub




End Module

From anywhere in your program you will now have access to all your forms or objects.

Example. From your options form you can call.

MainForm.Backcolor = "Blue" etc.....

You need to make sure you set your startup object to Sub Main

You go to Project/Properties and choose what you would like in the start up dropdown.


DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
Much thanks!

You'll probably see me posting again (...and again...).

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top