Publishing System Settings Logout Login Register
Creating a password screen
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on April 16th, 2008
23145 views
Visual Basic
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 *
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Blynx

My name's Josh, and I specialize in photoshop, after effects and html.

If you want to talk to me, check out my profile for contact details.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top