[RESOLVED] Sub Main()-Guidelines
hello everyBody,
what is the importance of using Sub Main() as startup.
Is it diff from using any particular form as startup.
Are there anythings that needs to be specially addressed to especially when working with db related applns if Sub Main() is used as startup.
Guidelines on this would be appreciated.
Thankyou. :thumb: :wave:
Re: Sub Main()-Guidelines
There are various reasons you might use Sub Main, such as when you don't want a form to show at all, or you want to use code to choose which form to show (perhaps based on the day of the week, or command line parameters), or you want to run some code before any forms are loaded, etc.
In terms of the way you use it, there is almost no difference between that and Form_Load - the only thing I can think of at the moment is ending your program in that routine, which for Sub Main is simply "Exit Sub", whereas in a form it is more complex.
Re: Sub Main()-Guidelines
Using Sub Main you could do some checking like if you can connect to the database or not before actually showing any form.
Re: Sub Main()-Guidelines
is there any concept of coming back to the submain when the appln is ended or its use is over once the primary form is loaded
Re: Sub Main()-Guidelines
I think you can call the Main procedure when your main form is being unloaded.
Re: Sub Main()-Guidelines
I use to show a splash screen while checking for program updates. If a new update is available then a different form is shown at start up
Re: Sub Main()-Guidelines
You can also write non-GUI programs with no Form in them at all. These begin and end with Sub Main(). They do a job and then complete. That job itself may involve numerous subroutines and functions and even Classes. Such programs are structured more like an old QBasic/QuickBasic program in many regards.
With a slight "tweak" to the compiled EXE such programs can even be turned into Console programs that interact with the user via StdIn/StdOut/StdErr or via Console Device APIs. Such programs can even be used on a Web server as CGI (Common Gateway Interface) programs.
A program written as a Windows Service is typically expected to process command-line parameters to decide what it was called to do and to perform certain functions that may not involve it entering Service mode. Such a Service program might be run by an admin to install or uninstall itself as a Service.
But probably the most common use for setting Sub Main() as a program's startup "object" is to perform initialization functions. This might involve things like calling InitCommonControls() which should be done before loading the first Form if you want to use "XP styles." Or it might be used to examine command-line parameters to decide which Form to load initially.
Re: Sub Main()-Guidelines
Quote:
Originally Posted by VBFnewcomer
is there any concept of coming back to the submain when the appln is ended or its use is over once the primary form is loaded
If your Sub Main() loads the main Form modelessly it continues running at the next statement immediately. Typically it only does a very little bit of additional work, but in any case it runs to the end and completes.
If Sub Main() loads the Form modally it halts until the Form unloads, after which it finishes running beginning at the next statement.
Re: Sub Main()-Guidelines
Thanks everybody. :afrog:
dilettante what if I load MDI
Re: Sub Main()-Guidelines
What is it that you are after? For MDI you can just use its unload event to perform whatever it is that you want to be done when your application is closing.
Re: Sub Main()-Guidelines
I just wanted to know if MDI is classified under Modal/non-modal
Re: Sub Main()-Guidelines
The Multiple Document Interface (MDI) was designed to simplify the exchange of information among documents, all under the same roof. With the main application, you can maintain multiple open windows, but not multiple copies of the application. Data exchange is easier when you can view and compare many documents simultaneously.
An MDI application must have at least two Forms, the parent Form and one or more child Forms. Each of these Forms has certain properties. There can be many child forms contained within the parent Form, but there can be only one parent Form.
Modal/Nonmodal is a property of a Child Form.
A modal window has exclusive focus, meaning, it requires user input before any other action can take place. Controls outside of the modal window will not take any user interaction until the modal is dismissed.
A modeless window is just the opposite, meaning, they don't require immediate user input before being closed or for interaction with other controls to take place.
Hope this helps...
Re: Sub Main()-Guidelines
still the questin if MDI is under modal/non modal. or simply put is MDI susceptible to modal manipulations
Re: Sub Main()-Guidelines
You can put only one MDI form in your project. It is a container for all the forms whose MDIChild property is set to True. i.e. Those forms will open inside the MDI Form window.
Take for example your Ms-Word Application. The Ms-Word window is MDI window. All your documents open inside that window. Those are child windows.
The question of MDI form being modal or non-modal is irrelevant. By common sense you would never open an MDI form modally. It might be possible to open it modal, but I don't see any point in doing that. It is not a dialog, it is a container.
Pradeep :)
Re: Sub Main()-Guidelines
Quote:
It might be possible to open it modal
not possible. Try
Code:
Sub main()
MsgBox "one"
MDIForm1.Show vbModal
MsgBox "two"
End Sub
Thanks for koolsid for pointing it out. :thumb:
Ok Iam satisfied with the info given by members.
Just for record the MDI acts modaless and continues to run the next statement in the sub main
Thanks again :wave: :afrog: