counter>

widget

Friday, November 1, 2013

Totorial Cara Membuat Login Visual Basic 6.0

2.1 Menu Selamat Datang

Pertama-tama, Anda perlu merancang menu Selamat datang. Anda dapat mengikuti contoh sebagai berikut:
 
Dalam bentuk ini, Anda harus memasukkan tiga tombol perintah dan mengatur properti mereka sebagai berikut:

Propery Name Setting
Form name frmMainMenu
command button 1  Name cmdRegister
command button 1 Caption Register
command button 2 Name cmdLogin
command button 2 Caption Login
command button 3 Name cmdCancel
command button 3 Caption Cancel
Kode adalah sebagai berikut:
Private Sub cmdCancel_Click()
End
End Sub

Private Sub cmdLogin_Click()
Me.Hide
Login_form.Show
End Sub

Private Sub cmdRegister_Click()
Me.Hide
Register.Show End Sub
* menggunakan Me.Hide adalah pilihan yang lebih baik kemudian menggunakan frmMainMenu.Hide karena kode program Anda akan lebih tepat dan lebih mudah dibaca.
 
29.2 Formulir Pendaftaran

Jika pengguna baru klik tombol Register, formulir pendaftaran akan muncul. Contoh yang diilustrasikan sebagai berikut:

Pendaftaran bentuk ini terdiri dari dua kotak teks, tiga tombol perintah dan kontrol ADO. Sifat mereka diatur sebagai berikut:
Propery Name Setting
Form name frmRegister
textbox 1 name txtName
textbox 2 name txtpassword
textbox 2 PasswordChar *
command button 1 name cmdConfirm
command button 1 Caption Confirm
command button 2 name cmdClear
command button 2 Caption Clear
command button 3 name cmdCancel
command button 3 Caption Cancel
ADO control name adoUserInfo
 
dicatat bahwa PasswordChar dari textbox 2 ditetapkan sebagai * yang berarti orang lain tidak akan dapat melihat karakter yang sebenarnya dimasukkan oleh pengguna, mereka hanya akan melihat simbol *.

Kode adalah sebagai berikut:
Private Sub cancel_Click( )
End
End Sub

Private Sub cmdClear_Click( )
txtName.Text = ""
txtpassword.Text = ""


End Sub

Private Sub cmdConfirm_Click()
adoUserInfo.Recordset.AddNew

adoUserInfo.Recordset.Fields("username") = txtName.Text
adoUserInfo.Recordset.Fields("password") = txtpassword.Text
adoUserInfo.Recordset.Update


Me.Hide

Login_form.Show


End Sub
 

 

29.3 The Menu Login

The Login Menu diilustrasikan sebagai berikut:


Ada dua kotak teks dan tombol perintah, sifat mereka ditetapkan sebagai berikut:
Propery Name Setting
Textbox 1 name txtName
Textbox 2 name txtpassword
Command button 1 name cmdLogin
Command button 1 Caption Login
Form name Login_form
Kode adalah sebagai berikut:
Private Sub cmdLogin_Click()

Dim usrname As String
Dim psword As String
Dim usernam As String
Dim pssword As String
Dim Msg As String


Register.UserInfo.Refresh
usrname = txtName.Text
psword = txtpassword.Text



Do Until Register.UserInfo.Recordset.EOF
If Register.UserInfo.Recordset.Fields("username").Value = usrname And Register.UserInfo.Recordset.Fields("password").Value = psword Then
Me.Hide
frmLibrary.Show

Exit Sub

Else
frmRegister.UserInfo.Recordset.MoveNext
End If

Loop

Msg = MsgBox("Invalid password, try again!", vbOKCancel)
If (Msg = 1) Then
Login_form.Show
txtName.Text = ""
txtpassword = ""


Else
End
End If

End Sub
 
29,4 Utama Database Manager

Database manager utama digambarkan sebagai berikut:
Sifat-sifat semua kontrol yang tercantum dalam tabel di bawah ini:
 
Propert Name Setting
Form name frmLibrary
ADO control name adoLibrary
ADO visible False
TextBox 1 name txtTitleA
TextBox 2 name txtAuthor
TextBox 3name txtPublisher
TextBox 4 name txtYear
TextBox 5 name txtCategory
Command button 1 name cmdSave
Command button 1 caption &Save
Command button 2 name cmdNew
Command button 2 caption &New
Command button 3 name cmdDelete
Command button 3 caption &Delete
Command button 4 name cmdCancel
Command button 4 caption &Cancel
Command button 5 name cmdNext
Command button 5 caption N&ext
Command button 6 name cmdPrevious
Command button 6 caption &Previous
Command button 7 name cmdExit
Command button 7 caption E&xit

Kode adalah sebagai berikut:
 
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtAuthor.Text = ""
txtPublisher.Text = ""
txtYear.Text = ""
txtCategory.Text = ""

End Sub

Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
adoLibrary.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"

End If

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdNew_Click()
adoLibrary.Recordset.AddNew


End Sub

Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveNext
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MovePrevious

End If
End If
End Sub

Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MovePrevious
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveNext

End If
End If
End Sub

Private Sub cmdSave_Click()

adoLibrary.Recordset.Fields("Title").Value = txtTitle.Text
adoLibrary.Recordset.Fields("Author").Value = txtAuthor.Text
adoLibrary.Recordset.Update

End Sub
 

No comments:

Post a Comment