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. Display a form in Sub Main()

Display a form in Sub Main()

Scheduled Pinned Locked Moved Visual Basic
csharphelp
10 Posts 6 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.
  • M Offline
    M Offline
    Mahesh1679
    wrote on last edited by
    #1

    Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

    S S M B 5 Replies Last reply
    0
    • M Mahesh1679

      Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

      S Offline
      S Offline
      sumit21
      wrote on last edited by
      #2

      well its very difficult from this code to pointout ur error but i got two points 1. check ur startup object. is it sub main ? 2. u are writing dim frm as ew form1() istead try out public frm as new form1() even if this does not work, then u better make a module and write the staatement there public frm as new form1() then in main u can use frm.show() hope this will work sumit

      M 1 Reply Last reply
      0
      • M Mahesh1679

        Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

        S Offline
        S Offline
        Sunil Gidwani
        wrote on last edited by
        #3

        If you want to open that form when your application starts then why dont you make it as startup object.

        1 Reply Last reply
        0
        • S sumit21

          well its very difficult from this code to pointout ur error but i got two points 1. check ur startup object. is it sub main ? 2. u are writing dim frm as ew form1() istead try out public frm as new form1() even if this does not work, then u better make a module and write the staatement there public frm as new form1() then in main u can use frm.show() hope this will work sumit

          M Offline
          M Offline
          Mahesh1679
          wrote on last edited by
          #4

          Thanks My start up object is Sub main. I have tried all the tips given above. I would like to tell you some information.... My application starts executing from Sub Main(). Iam checking a condition in Sub Main procedure and based on that i displaying a form. So when i tried to do that form is displayed for few seconds and the application is terminated. and i assure that there are no errors like logical or syntax error in coding I hope that there must some other steps to display a form in Sub Main Pls help me to find a solution...... Thanks

          R 1 Reply Last reply
          0
          • M Mahesh1679

            Thanks My start up object is Sub main. I have tried all the tips given above. I would like to tell you some information.... My application starts executing from Sub Main(). Iam checking a condition in Sub Main procedure and based on that i displaying a form. So when i tried to do that form is displayed for few seconds and the application is terminated. and i assure that there are no errors like logical or syntax error in coding I hope that there must some other steps to display a form in Sub Main Pls help me to find a solution...... Thanks

            R Offline
            R Offline
            rwestgraham
            wrote on last edited by
            #5

            OK, In VB6 you could do this and then if you displayed a form the application would continue to run. In VB.NET even if you show a form in Sub Main, when Sub Main ends, the form will be destroyed and the application will terminate. There is a simple fix for this. The critical line of code you need is in bold: ------------------------------------------------------ Sub Main() ...your initialization code goes here ... If ...your conditions are met... Then MyForm.Show Application.Run() End If End Sub -------------------------------------------------------- Robert

            1 Reply Last reply
            0
            • M Mahesh1679

              Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

              S Offline
              S Offline
              sumit21
              wrote on last edited by
              #6

              hey, it means there is some condition which is forcing ur program to end. i also had faced such problem previously then i put message box whereever i was doubtful in my code u can also put msgbox in formload of form1. this will tell u is form1 is loading or not then u can put the msgbox in other functions of form1 this may tell u the code which is creating problem my suggestion is to use msgbox and try to debug ur code

              1 Reply Last reply
              0
              • M Mahesh1679

                Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

                M Offline
                M Offline
                Mitch F
                wrote on last edited by
                #7

                Hello, You could try to put your conditional statements inside of the Form Load event. If the conditions are not met, you could then use Me.Close() to exit. For an example,

                If <conditions> then
                'Do your stuff here if it is met
                Else
                Me.Close() 'Exit the application since the conditions are not met.
                End If

                I hope this helps, Programmer2k4 My sig: "And it is a professional faux pas to pay someone else to destroy your computer when you are perfectly capable of destroying it yourself." - Roger Wright I now use my CodeProject Blog! Most recent blog post: March 24

                1 Reply Last reply
                0
                • M Mahesh1679

                  Hi To ALL! In VB.NET, i need to display a form in Sub Main().I have written code something like this but its not working. Pls help me ... Public Sub main() dim frm as new form1() frm.show() End sub Thanks Mahesh

                  B Offline
                  B Offline
                  Benjamin Liedblad
                  wrote on last edited by
                  #8

                  I had this one about 2 years ago... I had put some code inside my "form1" and found that the code ran, but the form seemed to never appear. If you put a DoEvents after the show, then a Msgbox, you'll see what's happening... Your form is actually loading, but the program is exiting after the form.show method. If you want to load the form and not exit "Main" until you close the form try using the ShowDialog method of the form instead of the Show method. I think that's what you are looking for.

                  M 2 Replies Last reply
                  0
                  • B Benjamin Liedblad

                    I had this one about 2 years ago... I had put some code inside my "form1" and found that the code ran, but the form seemed to never appear. If you put a DoEvents after the show, then a Msgbox, you'll see what's happening... Your form is actually loading, but the program is exiting after the form.show method. If you want to load the form and not exit "Main" until you close the form try using the ShowDialog method of the form instead of the Show method. I think that's what you are looking for.

                    M Offline
                    M Offline
                    Mahesh1679
                    wrote on last edited by
                    #9

                    Thanks Alot! It finally worked as Benjamin Liedblad said. I would like to thank all of you who spared your precious time for me. Thanks

                    1 Reply Last reply
                    0
                    • B Benjamin Liedblad

                      I had this one about 2 years ago... I had put some code inside my "form1" and found that the code ran, but the form seemed to never appear. If you put a DoEvents after the show, then a Msgbox, you'll see what's happening... Your form is actually loading, but the program is exiting after the form.show method. If you want to load the form and not exit "Main" until you close the form try using the ShowDialog method of the form instead of the Show method. I think that's what you are looking for.

                      M Offline
                      M Offline
                      Mahesh1679
                      wrote on last edited by
                      #10

                      Thanks Alot! It finally worked as Benjamin Liedblad said. I would like to thank all of you who spared your precious time for me. Thanks

                      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