[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?
Re: [2005] Application.Quit() giving an error
Bumpedy Bump, Does anyone know, I still have not figured it out
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
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
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.
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!
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 ...
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