Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Start up module for VB.NET Windows Application??

Start up module for VB.NET Windows Application??

Scheduled Pinned Locked Moved Visual Basic
csharpquestiondiscussion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barney_1972
    wrote on last edited by
    #1

    In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks

    A O 2 Replies Last reply
    0
    • B barney_1972

      In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks

      A Offline
      A Offline
      AliAmjad
      wrote on last edited by
      #2

      Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'. For Example:

      Sub New

      'Initialize Code here

      End Sub

      Hope it helps !

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      B 1 Reply Last reply
      0
      • A AliAmjad

        Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'. For Example:

        Sub New

        'Initialize Code here

        End Sub

        Hope it helps !

        AliAmjad(MCP) First make it Run THEN make it Run Fast!

        B Offline
        B Offline
        barney_1972
        wrote on last edited by
        #3

        I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.

        A 1 Reply Last reply
        0
        • B barney_1972

          In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks

          O Offline
          O Offline
          Ocean47
          wrote on last edited by
          #4

          first create a Start up module I alway call it mMain and than create the Main() sub. than from the project menu select properties then from the application tab select the startup object as sub Main() in sub Main you should put the following code at the end: Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainFrm)

          B 1 Reply Last reply
          0
          • B barney_1972

            I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.

            A Offline
            A Offline
            AliAmjad
            wrote on last edited by
            #5

            When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.

            Public Sub New()
                MyBase.New()
            
                'This call is required by the Windows Form Designer.
                InitializeComponent()
            
                'Add any initialization after the InitializeComponent() call
                'Your code goes here....    
            
            End Sub
            

            I think you should buy a book because It'll really help you to clear your concepts ! hope it helps !

            AliAmjad(MCP) First make it Run THEN make it Run Fast!

            B 1 Reply Last reply
            0
            • O Ocean47

              first create a Start up module I alway call it mMain and than create the Main() sub. than from the project menu select properties then from the application tab select the startup object as sub Main() in sub Main you should put the following code at the end: Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainFrm)

              B Offline
              B Offline
              barney_1972
              wrote on last edited by
              #6

              When i uncheck the 'Enable application framework' though what implication does this have?

              1 Reply Last reply
              0
              • A AliAmjad

                When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.

                Public Sub New()
                    MyBase.New()
                
                    'This call is required by the Windows Form Designer.
                    InitializeComponent()
                
                    'Add any initialization after the InitializeComponent() call
                    'Your code goes here....    
                
                End Sub
                

                I think you should buy a book because It'll really help you to clear your concepts ! hope it helps !

                AliAmjad(MCP) First make it Run THEN make it Run Fast!

                B Offline
                B Offline
                barney_1972
                wrote on last edited by
                #7

                AliAmjad Thanks, i do have a book and have seen the code you mention before. But for some reason it is not in my current form. When i select 'show all files' im the solution explorer, a plus sign appears next to my form which, if expanded, show me a Form.Designer.vb file and a Form.resx file. I can see some code with 'Mybase.Disposing' in the Form.Designer.vb file but cannot find the form constructor anywhere. I can create a constructor, with the same code as your comment and the IDE doesn't complain, but i would like to know why it is'nt there in the first place. I have also tried adding in another form, just in case the code was accidentily deleted but this was the same.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups