|
-
Jan 28th, 2009, 07:28 AM
#1
Thread Starter
Frenzied Member
-
Jan 28th, 2009, 08:28 AM
#2
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.
-
Jan 28th, 2009, 08:29 AM
#3
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.
-
Jan 28th, 2009, 08:40 AM
#4
Thread Starter
Frenzied Member
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
-
Jan 28th, 2009, 08:43 AM
#5
Re: Sub Main()-Guidelines
I think you can call the Main procedure when your main form is being unloaded.
-
Jan 28th, 2009, 11:20 AM
#6
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
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Jan 28th, 2009, 04:16 PM
#7
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.
-
Jan 28th, 2009, 04:23 PM
#8
Re: Sub Main()-Guidelines
 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.
-
Jan 29th, 2009, 12:19 AM
#9
Thread Starter
Frenzied Member
Re: Sub Main()-Guidelines
Thanks everybody.
dilettante what if I load MDI
-
Jan 29th, 2009, 02:25 AM
#10
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.
-
Jan 29th, 2009, 02:41 AM
#11
Thread Starter
Frenzied Member
Re: Sub Main()-Guidelines
I just wanted to know if MDI is classified under Modal/non-modal
-
Jan 29th, 2009, 03:03 AM
#12
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...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 29th, 2009, 03:21 AM
#13
Thread Starter
Frenzied Member
Re: Sub Main()-Guidelines
still the questin if MDI is under modal/non modal. or simply put is MDI susceptible to modal manipulations
-
Jan 29th, 2009, 03:33 AM
#14
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
Last edited by Pradeep1210; Jan 29th, 2009 at 03:36 AM.
-
Jan 29th, 2009, 04:26 AM
#15
Thread Starter
Frenzied Member
Re: Sub Main()-Guidelines
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. 
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|