Results 1 to 15 of 15

Thread: [RESOLVED] Sub Main()-Guidelines

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Resolved [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.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Sub Main()-Guidelines

    I think you can call the Main procedure when your main form is being unloaded.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Sub Main()-Guidelines

    Thanks everybody.
    dilettante what if I load MDI

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Sub Main()-Guidelines

    I just wanted to know if MDI is classified under Modal/non-modal

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Sub Main()-Guidelines

    still the questin if MDI is under modal/non modal. or simply put is MDI susceptible to modal manipulations

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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
  •  



Click Here to Expand Forum to Full Width