Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1053257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:13:26+00:00 2026-05-16T17:13:26+00:00

I have a VB.NET app that is behaving strangely (or perhaps not strangely at

  • 0

I have a VB.NET app that is behaving strangely (or perhaps not strangely at all and I’m just missing something).

I have a login form that when the user clicks OK and logs in successfully it loads the main application form.

However when I show the main form and close the login form, the app is firing the shutdown event.

Is this because the app thinks that the login form is the only form open and thus fires the shutdown event?

Here is the code for the login routine, when I call Me.Close() at the end is when the shutdown event is fired. Am I doing things out of order? I used to do it this way in VB6 with no problems (I know they’re a lot different).

Note, it’s nothing in frmMain either, this happens no matter what form I try to open.

Thanks.

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

    'iLoginResult = 0 : Success
    '               1 : Invalid user name or password
    '               2 : Other login error
    '               3 : User not authorized

    Dim iLoginResult As Integer = 2
    Dim sTopLabel As String = ""
    Dim sBottomLabel As String = ""

    Me.Cursor = Cursors.WaitCursor

    Try
        If Me.txtUserName.Text.ToString.Trim = "" Or Me.txtPassword.Text.ToString.Trim = "" Then
            MessageBox.Show("Enter a user name and password before continuing.", "DocGen", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Try
        End If
        iLoginResult = modGeneral.bLogin(Me.txtUserName.Text.ToString.Trim, Me.txtPassword.Text.ToString.Trim)
        Select Case iLoginResult
            Case 1 : sTopLabel = "The user name or password is incorrect" : sBottomLabel = "Check your user name then type your password again."
            Case 2 : sTopLabel = "General login error" : sBottomLabel = "Contact your information technology department."
            Case 3 : sTopLabel = "Unauthorized access" : sBottomLabel = "Contact your information technology department to gain access to this system."
        End Select
        If iLoginResult > 0 Then
            RaiseDialog(sTopLabel, sBottomLabel)
            Me.txtPassword.Text = ""
            Me.txtUserName.Focus()
            Me.txtUserName.SelectAll()
        End If
    Catch ex As Exception
        RaiseError("", "frmLogin.btnOK_Click", Err.Number, Err.Description)
    End Try

    Me.Cursor = Cursors.Default

    If iLoginResult = 0 Then
        If Me.cmbEnvironment.Text = "Development" Then modGeneral.gbIsProduction = False
        frmMain.Show()
        Me.Close()
    End If

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:13:26+00:00Added an answer on May 16, 2026 at 5:13 pm
    If iLoginResult = 0 Then
            If Me.cmbEnvironment.Text = "Development" Then modGeneral.gbIsProduction = False
            frmMain.Show()
            Me.Close()
        End If
    

    This is what is doing it. You are opening the MainForm (frmMain) from the Login Form, thus when you close the login form the MainForm gets disposed, causing your program to end.

    What you should be doing is opening your login form and main form from some other startup object.

    Further Explanation

    So By Using Sub Main(ByVal args() As String) you can do something like this

    <STAThread)> _
    Public Shared Sub Main(ByVal args() As String)
       Using login as New LoginForm
          If login.ShowDialog <> DialogResult.OK Then
             'End the Application or Whatever if the login isn't valid
          End If
       End Using
    
       frmMain.Show()
    
       Application.Run()
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET Login App that creates a cookie called 'ASP_LOGIN77' and gives
I have a .NET app that allows a user to choose their own language
I have asp.net mvc app that shows varios events. All events stored in a
I have a .NET 2.0 app that runs just fine on XP and Vista,
I have an ASP.NET MVC3 app that features a form with a nested-table input
We have an ASP.NET webforms app that has try/catch blocks all throughout. In the
I have an ASP.NET app that gets its data form an external service, via
I have an ASP.NET MVC app that stores all SQL DateTime in UTC, so
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I have a .NET client app that intermittently loses connection to a UNC share

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.