How to Create Simple log-in
1st Step: Create a Log-in Design.
Ø Drag a 2 label onto the form and
change the label TEXT in properties.
o
For
1st label change the TEXT into “User Name :”
o
For
2nd label change the TEXT into “Password :”
Ø Drag a 2 textbox onto the form and
change the textbox TEXT in properties.
o
For
1st textbox change the TEXT into “txtUserName”
o
For
2nd textbox change the TEXT into “txtPassword”
Ø Drag a 1 button onto the form and
change the Button NAME and TEXT in properties.
o
For
Button TEXT
§ For 1st Button Change the TEXT into “Log-In”.
o
For
Button NAME
§ For 1st Button Change the
NAME into “btnLogIn”.
2nd Step: Start Coding
Ø To Start Coding, double click the
Form.
Ø Declare the Variables.
o
Dim
dgUserName,dgPassword as String.
§ dgUserName is a value entered in the First
Textbox.
§ dgPassword is a value entered in the Second Textbox.
Ø Go back to design then double click
button.
o
Code
for the Log-In button.
Private Sub btnLogIn_Click()Handles
btnLogIn.Click
If
txtUserName.Text = "" Then
MsgBox("Please
Input UserName!")
ElseIf txtPassword.Text = ""
Then
MsgBox("Please
Input Password!")
ElseIf txtUserName.Text = "User" And txtPassword.Text = "user123" Then
MsgBox("Log-In
Success!")
txtUserName.Clear()
txtPassword.Clear()
Else
MsgBox("Invalid UserName or Password")
End
If
End Sub
3rd
Step: Run the Program.
Ø Click to start Debugging Button (F5).
Source Code:
Public Class Form1
Private Sub btnLogIn_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogIn.Click
If
txtUserName.Text = "" Then
MsgBox("Please
Input UserName!")
ElseIf
txtPassword.Text = "" Then
MsgBox("Please
Input Password!")
ElseIf
txtUserName.Text = "User" And
txtPassword.Text = "user123"
Then
txtPassword.Text = "user123"
Then
MsgBox("Log-In
Success!")
txtUserName.Clear()
txtPassword.Clear()
Else
MsgBox("Invalid
UserName or Password")
End If
End Sub
End Class
No comments:
Post a Comment