Visual Basic (Microsoft Studio 2005) Help (Loops)

jo5h

Daemon Poster
Messages
1,034
In my visual Basic programming class we were given an assignment to create an application that checks the password at sign-on time (when the application starts). The application will display an input box requesting a password. If the password is correct, it will display the form (me.show) If if the password is incorrect a message box will display "Re-enter Password", if the password is incorrect 3 times a message will display " contact your administrator" then will exit the application. Now my question is When the password is correct It has to display the form. I have everything else working just not the form display. Here is my code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Variables
Dim n As Integer
Dim strpassword As String = "begin"
n = 0


'3 chances to get the password right

Do Until n = 3
strpassword = InputBox("Please enter your password", )

'IF the password is correct it will display vb is great

If strpassword = "begin" Then
Me.Show()
Else
MessageBox.Show("Re-Enter Password", "Incorrect Password", MessageBoxButtons.OK)
n = n + 1
End If
Loop

'If n = 3 the program will close

If n = 3 Then
MessageBox.Show("Invalid Password...Contact your Administrator", "Incorrect Password", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End
End If
End Sub

So i was wondering if anyone here could point me in the direction of what im doing wrong.. feel free to edit the code.
 
what is the name of the form itself? If it's not "ME", then try frmform.Show()

Also, the second if statement should be before "loop"
 
Celegorm, "me" can always be used. It refers to the current object. I c# I believe the keyword is "this". But yeah, "me" should work.
 
Well, from what I see he's not trying to load the form. You can't use a message box with an unloaded form. The form is loaded it is just invisible.
 
I figured it out

after the password is entered correctly

me.show (which is the form)
exit sub
 
Back
Top Bottom