• home
  • forum
  • my
  • kt
  • download
  • Visual Basic Tutorial - Simple Login Script

    Author: 2007-09-06 10:07:51 From:

    Hello, and welcome to my simple login form tutorial. This is situated on the fact that you are using Visual Basic 6.0

    1. Starting off you are going to need to open up Visual Basic 6.0 Development window, and create a standard .exe file

    2. Now you need to drag onto the form the correct command property.

    These are as follows:

    2 Command Buttons
    2 Text Boxes
    2 Labels

    Set the following properties for the different controls.

    Command Button 1
    Name: cmdLogin
    Caption: Login

    Command Button 2
    Name: cmdClose
    Caption: Close Program

    Text Box 1
    Name: txtUsername
    Text: Leave this empty

    Text Box 2
    Name: txtPassword
    Text: Leave this empty
    PasswordChar: * (Reccommended so that the text appears as stars, added security.)

    Label 1
    Caption: Username:

    Label 2
    Caption: Password

    Now that you have the correct controls on the screen then we can get down to the coding!

    In order to access the code of the program, right click anywhere on the form and click on view code.

    Code:
    'Global Variables
    Dim Username As String                       'Username Variable
    Dim Password As String                       'Password Variable
     
    Private Sub cmdLogin_Click()
     
    Username = "TestUser1"              'What the Username Variable is
    Password = "TestUser1"              'What the Password Variable is
     
    'If Statement Starting Here
    'It States that if the username is = to text box and password is = password text box, then it should login, else display error message!
    If Username = txtUsername And Password = txtPassword Then
     
               frmLoginSuccess.Show    'Shows the Login Success Form
               frmLoginScreen.Hide       'Hides the Login Screen
     
    Else
     
    'A Message box that displays you have entered the wrong username and password
               
    MsgBox ("You have entered the wrong username and password")
     
    End If
     
    End Sub
     
    Private Sub cmdClose_Click()
     
    Unload Me      'Closes the program
     
    End Sub
    This is a basic piece of code that checks that what is etnered in the username box, and what is entered in the password box, is equal to what the username and password variables have been set at.

    3. Now you need to name the forms. Click the form and go to the name property, and call the form frmLoginScreen.

    4. Now create a new form. The way to do this is to right click in the project explorer area, and click on new, then select form. Now call this form frmLoginSuccess.

    5. Now run the program and see if it works. In theory, when you have entered the correct username and password, it should hide the Login Form and show the Login Success form.

    Well that is it!

    Test It, and if there are any problems, then simply post here or PM me.

    --
    Zenax


    Regards,
    Zenax

    **************************************
    My new ZenTuts website coming soon!
    Written in mixtures of HTML, PHP, MySQL

    Please PM me a tutorial if you want.

    Place the tutorial content in a HTML file, in correct order that its supposed to be followed. All images must be included as well in ZIP. DO NOT HOTLINK IMAGES!

    Your name will be shown on the tutorials page. Please include a avatar to use for the tut or yourself if you so wish!

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      .NET (8)
      Buttons (3)
      Database Related (7)
      Date and Time (1)
      Development (3)
      Error Handling (2)
      File Manipulation (5)
      Introduction to Visual Basic (9)
      Miscellaneous (2)
      Multimedia (9)
      Networking (9)
      Security (1)
      VB Script (6)

    New

    Hot