|
-
Oct 27th, 2002, 10:45 PM
#1
Thread Starter
Member
Logon Validation
Hey guys,
I'm very new to VB.net and am having a problem with a logon screen.
Here's the code i am using:
Main Form:
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frmLogon As New LogonDialog()
Dim bLogonSuccessful As Boolean = False
Dim sFailureMessage As String
If frmLogon.ShowDialog() = DialogResult.OK Then
If frmLogon.txtUser.Text = "username" Then
If frmLogon.txtPassword.Text = "password" Then
bLogonSuccessful = True
Else
sFailureMessage = "Invalid Password!"
End If
Else
sFailureMessage = "Invalid User ID!"
End If
Else
sFailureMessage = "Logon Attempt Cancelled"
End If
If Not bLogonSuccessful Then
MessageBox.Show(sFailureMessage, "Logon Failed", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
End Sub
Logon Form:
VB Code:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Dim sUserID As String
Dim sPassword As String
If sUserID.Trim() = "" Then
MessageBox.Show("UserID cannot be blank" & "Please enter a proper UserID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPassword.Select()
Else
Me.DialogResult = DialogResult.OK
End If
End Sub
This is the error i am getting when i click OK on the logon form:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in login.exe
Additional information: Object reference not set to an instance of an object.
__________
Any help would be greatly appreciated
Thanks guys
Longshot
*edit: vB code added*
Last edited by longshot_zero; Oct 27th, 2002 at 10:53 PM.
-
Oct 27th, 2002, 11:05 PM
#2
Thread Starter
Member
Re: Logon Validation
Originally posted by longshot_zero
Logon Form:
VB Code:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Dim sUserID As String
Dim sPassword As String
If sUserID.Trim() = "" Then
MessageBox.Show("UserID cannot be blank" & "Please enter a proper UserID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPassword.Select()
Else
Me.DialogResult = DialogResult.OK
End If
End Sub
ahh got it... a case of brain fade on my behalf...
the above should have read:
VB Code:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Dim sUserID As String
Dim sPassword As String
sUserID = txtUsername
sPassword = txtPassword
If sUserID.Trim() = "" Then
MessageBox.Show("UserID cannot be blank" & "Please enter a proper UserID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPassword.Select()
Else
Me.DialogResult = DialogResult.OK
End If
End Sub
However, for it to work i have also had to remove the ".trim()" from the code. Anyone know why this is?
Thanks in advance
-
Oct 27th, 2002, 11:06 PM
#3
PowerPoster
Set a break point and step through your code...
Find where it has the error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|