Hi welcome to my second tutorial.
This time i'll show you how to make a Password screen.
This was actually ment to be a system to protect my thumbdrive which I could modify as I needed but I thought i'd write a tutorial and be nice.
Okay to start i'm coding in VB 2008 Express so the code
MIGHT vary a little.
Start with a basic form.
Now create a label, leave the name as default, you can change the caption, I named mine Password for obvious reasons.
Now create a textbox and name it password
Create 2 buttons one for Ok and one for cancel.
Name them just like you did the textbox but name them ok and cancel.
You made the design. Good job. Now onto the hard part: Coding
Double click the OK button and enter this code.
Note I commented the code to explain
'Checks if the password is correct, also defines the password
If password.Text = "password" Then 'where password.text is whatever you named your textbox.text
MsgBox("Correct") 'Exactly as it says, replace this with whatever you want it to do.
Application.Exit() 'Closes the program if code is correct
Else
MsgBox("Incorrect") 'Exactly as it says, replace this with whatever you want it to do
End If
Double click the cancel button and add this code.
Application.Exit()
Run the program and try.
If it doesn't work don't give up. Just use DEBUG.
My full code which might give errors in previous versions is:
Public Class Form1
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
'Checks if the password is correct, also defines the password
If password.Text = "password" Then 'where password.text is whatever you named your textbox.text
MsgBox("Correct") 'Exactly as it says
Application.Exit()
Else
MsgBox("Incorrect") 'Exactly as it says
End If
End Sub
Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
Application.Exit()
End Sub
End Class
If you want to make the password show up as *s then click the textbox and change the PasswordChar setting to *