Results 1 to 8 of 8

Thread: [2005] Application.Quit() giving an error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Australia
    Posts
    237

    [2005] Application.Quit() giving an error

    When I click my Exit Program button, it says

    Code:
    Object reference not set to an instance of an object.
    And sometimes I don't quite remember but it says something along the line of

    RoundRobinPro is Disposed... (My Main app)

    This is my login form, which I have made, the code I use is below

    Code:
    Option Strict On
    Option Explicit On
    
    Public Class LoginForm1
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
            Dim quit As Boolean = True
            If SignupRadio.Checked Then
                If System.IO.Directory.Exists("C:\Program Files\Round Robin Pro\Variables\" & _
                UsernameTextBox.Text) Then
                    quit = False
                Else
                    System.IO.Directory.CreateDirectory("C:\Program Files\Round Robin Pro\Variables\" & _
                    UsernameTextBox.Text)
                    RoundRobinPro.Dir.UsernameDir = RoundRobinPro.fnc _
                    .CapitalizeString(UsernameTextBox.Text)
                    MsgBox("Your account has been created", MsgBoxStyle.OkOnly)
                End If
            End If
            Dim errorString As String = ""
            If LoginRadio.Checked Then
                If Not UsernameTextBox.Text.Length > 4 Then
                    quit = False
                    errorString &= "Your username must be atleast 5 characters long." & ControlChars.NewLine
                End If
                If Not PasswordTextBox.Text.Length > 4 Then
                    quit = False
                    errorString &= "Your password must be atleast 5 characters long." & ControlChars.NewLine
                End If
                If Not ConfirmPw_t.Text.Length > 4 Then
                    quit = False
                    errorString &= "Your confirm password must be atleast 5 characters long." & _
                    ControlChars.NewLine
                End If
            End If
    
            If quit Then
                Me.Close()
            Else
                MsgBox(errorString)
            End If
        End Sub
    
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Me.Close()
        End Sub
    
        Private Sub Timer123_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer123.Tick
            If SignupRadio.Checked Then
                ConfirmPw_t.Visible = True
                ConfirmPw_l.Visible = True
                LoginButton.Text = "Signup"
            Else
                ConfirmPw_t.Visible = False
                ConfirmPw_l.Visible = False
                LoginButton.Text = "Login"
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Application.Exit()
        End Sub
    End Class
    Anyone know what's wrong?
    Cheater's prosper, just not in a good way.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Australia
    Posts
    237

    Re: [2005] Application.Quit() giving an error

    Bumpedy Bump, Does anyone know, I still have not figured it out
    Cheater's prosper, just not in a good way.

  3. #3
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: [2005] Application.Quit() giving an error

    Instead of Application.Exit(), just try End. Like this:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            End
    End Sub

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [2005] Application.Quit() giving an error

    END is not a good practice, thought it may help you here it may become an unhealthy habit.
    You should create a try catch block or try to do yourform.hide instead of .close

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Application.Quit() giving an error

    End is a Legacy function from VB6 and shouldnt be used in .NET.

    Where are you creating the object "RoundRobinPro"? Seems its not created so when you try to access one of its properties or methods you will get that exact error.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: [2005] Application.Quit() giving an error

    Quote Originally Posted by RobDog888
    End is a Legacy function from VB6 and shouldnt be used in .NET.

    oh wow I wasn't aware it was bad practice. Learn something new every day
    Thanks!

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [2005] Application.Quit() giving an error

    It was the only way to end a BASIC program, because there was no window to close or object to dispose of. Forget that you can use End on a line by itself (End Sub and End Function are mandatory) and you'll save yourself a lot of grief in the future.

    As one of the posters here says, closing the form is like escorting your guests to the street after the party is over. Using End is like pushing them off the 25th floor balcony. Either way will get them to the street, and the balcony route is faster, but ...
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Application.Quit() giving an error

    yeah just look at the documentation for END, while its pretty complete documentation, there are several places in it where they advise against using it.

    http://msdn2.microsoft.com/en-us/lib...ba(VS.80).aspx

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