Results 1 to 4 of 4

Thread: [RESOLVED] VB.Net and Sub Main()

  1. #1

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Resolved [RESOLVED] VB.Net and Sub Main()

    Hey, this is just a throw out to all the techies here in the forums. I do most of my coding in C#, but I do answer a lot of questions in VB.Net and recently I find myself increasingly frustrated by the lack of an exposed Program class in VB.Net Windows Forms Applications.

    The reason I find this irritating is mainly in the case of questions about user validation. As i'm sure many of you already know and do, the best practice for user validation is not to run the program at all unless the user has been validated.

    Hypothetically, in a VB.Net application, the Sub Main() would probably look something like this:

    Code:
    Module Program
        Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            
            Dim success As Boolean
    
            Using login As New LoginForm
                success = (login.ShowDialog() = Windows.Forms.DialogResult.OK)
            End Using
    
            If success Then _
                Application.Run(New MainForm())
        End Sub
    End Class
    Unfortunately, unlike in C#, i've been completely unable to expose Sub Main() in VB.Net. Have any of you managed, or heard of a way to expose or override this sub in VB.Net?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: VB.Net and Sub Main()

    What version of VS are you using?

    If you are using VS2008, look into the Application Events object. You can expose this by clicking the View Application Events button on the Application tab of the project properties.

    From here you can access the startup & shutdown events of the application, among others.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.Net and Sub Main()

    In VB.NET you have to turn off the Application Framework in the project properties to be able to create your own Main method as an entry point. The thing is, you really shouldn't because that's one of the reasons that the Application Framework exists. Follow the WinForms Logon link in my signature to see how it's done in VB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: VB.Net and Sub Main()

    Excellent, thank you.

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