Sebelumnya aku telah menciptakan tutorial Cara Membuat Form Login, namun form login sebelumnya (versi 1) tidak memakai database, sehingga data login menyerupai username dan password, tidak dapat di edit dikala jadwal di jalankan atau tidak dapat di ganti, kali ini kita akan menciptakan sebuah Form Login dengan memakai database, database yang aku gunakan di sini yaitu Notepad, oke berikut tutorialnya :
1. Jalankan VB dengan project Standar Exe
Cara Menambahkan Module
2. Sebelum ke form, tambahkan terlebih dahulu module caranya :
Klik Menu Project > Add Module > Pilih Module > Klik Open
kemudian tuliskan script berikut :
1. Jalankan VB dengan project Standar Exe
Cara Menambahkan Module
2. Sebelum ke form, tambahkan terlebih dahulu module caranya :
Klik Menu Project > Add Module > Pilih Module > Klik Open
kemudian tuliskan script berikut :
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Function WriteIni(KeySection As String, KeyKey As String, KeyValue As String) As Boolean
Dim lngResult As Long, strFileName As String, AppPath As String
AppPath = App.Path
If Right(AppPath, 1) = "\" Then
strFileName = AppPath & "\routerosmikrotik.txt"
Else
strFileName = AppPath & "\routerosmikrotik.txt"
End If
lngResult = WritePrivateProfileString(KeySection, KeyKey, KeyValue, strFileName)
If lngResult = 0 Then
WriteIni = False
Else
WriteIni = True
End If
End Function
Public Function ReadIni(KeySection As String, KeyKey As String) As String
Dim lngResult As Long
Dim strFileName
Dim strResult As String * 50
AppPath = App.Path
If Right(AppPath, 1) = "\" Then
strFileName = AppPath & "\routerosmikrotik.txt"
Else
strFileName = AppPath & "\routerosmikrotik.txt"
End If
lngResult = GetPrivateProfileString(KeySection, KeyKey, strFileName, strResult, Len(strResult), strFileName)
If lngResult = 0 Then
ReadIni = "error"
Else
ReadIni = Left(strResult, lngResult)
End If
End Function
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Function WriteIni(KeySection As String, KeyKey As String, KeyValue As String) As Boolean
Dim lngResult As Long, strFileName As String, AppPath As String
AppPath = App.Path
If Right(AppPath, 1) = "\" Then
strFileName = AppPath & "\routerosmikrotik.txt"
Else
strFileName = AppPath & "\routerosmikrotik.txt"
End If
lngResult = WritePrivateProfileString(KeySection, KeyKey, KeyValue, strFileName)
If lngResult = 0 Then
WriteIni = False
Else
WriteIni = True
End If
End Function
Public Function ReadIni(KeySection As String, KeyKey As String) As String
Dim lngResult As Long
Dim strFileName
Dim strResult As String * 50
AppPath = App.Path
If Right(AppPath, 1) = "\" Then
strFileName = AppPath & "\routerosmikrotik.txt"
Else
strFileName = AppPath & "\routerosmikrotik.txt"
End If
lngResult = GetPrivateProfileString(KeySection, KeyKey, strFileName, strResult, Len(strResult), strFileName)
If lngResult = 0 Then
ReadIni = "error"
Else
ReadIni = Left(strResult, lngResult)
End If
End Function
Di jadwal ini aku memakai 2 form, bila anda belum tahu cara menciptakan 2 form / menambahkan form, anda dapat membacanya disini :3. Untuk Form1, Tambahkan 2 label, 2 text box dan 2 command button, atur tampilan dan lebarnya sehingga menyerupai ini :
Membuat Program Menggunakan Lebih dari 1 Form
Tool Box | Properties | Description |
Form1 | Start Up | Center Screen |
Label 1 | Caption | Username |
Label 2 | Password | |
Textbox 1 | Text | (Kosong) |
Textbox 2 | (Kosong) | |
Command 1 | Caption | LOGIN |
Command 2 | END | |
All | Font Size | 10 |
dan untuk form 2 sama dengan form 1, tambahkan 2 label, 2 text box, 2 command button, atur menyerupai ini :
Tool Box | Properties | Description |
Form1 | Start Up | Center Screen |
Label 1 | Caption | CHECK DATA |
Label 2 | TRY LOGIN | |
Textbox 1 | Text | (Kosong) |
Textbox 2 | (Kosong) | |
Command 1 | Caption | Login |
Command 2 | End | |
All | Font Size | 10 |
4. Jika sudah tuliskan script berikut untuk form1
Private Sub Command2_Click()
'Script untuk menghentikan program
End
End Sub
Private Sub Command1_Click()
'Proses yang akan terjadi bila data login di database sama dengan data yang di input
If Text1.Text = ReadIni("DATA", "Username") And Text2.Text = ReadIni("DATA", "Password") Then
form1.Hide
form2.Show
form2.Text1.Enabled = False
form2.Text2.Enabled = False
form2.Text1 = ""
form2.Text2 = ""Command1.Caption = "CHECK DATA"
'Pesan bila text1 dan 2 kosong dikala command1 "Login" di klik
ElseIf Text1.Text = "" Or Text2.Text = "" Then
MsgBox "Please, Complete The Form", vbInformation, "Routeros Mikrotik"
'Pesan bila salah memasukan data login
Else
MsgBox "Username or Password Invalid, Please Try Again", vbCritical, "Routeros Mikrotik"
Call Form_Load
End If
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
'Script untuk menghentikan program
End
End Sub
Private Sub Command1_Click()
'Proses yang akan terjadi bila data login di database sama dengan data yang di input
If Text1.Text = ReadIni("DATA", "Username") And Text2.Text = ReadIni("DATA", "Password") Then
form1.Hide
form2.Show
form2.Text1.Enabled = False
form2.Text2.Enabled = False
form2.Text1 = ""
form2.Text2 = ""Command1.Caption = "CHECK DATA"
'Pesan bila text1 dan 2 kosong dikala command1 "Login" di klik
ElseIf Text1.Text = "" Or Text2.Text = "" Then
MsgBox "Please, Complete The Form", vbInformation, "Routeros Mikrotik"
'Pesan bila salah memasukan data login
Else
MsgBox "Username or Password Invalid, Please Try Again", vbCritical, "Routeros Mikrotik"
Call Form_Load
End If
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
dan tuliskan script berikut di form2
[DATA]
Username=Routeros Mikrotik
Password=qwerty
Ganti kata Routeros Mikrotik dengan kata untuk login, dan qwerty untuk password
save file
6. Jalankan program
Sekian tutorial kali ini agar bermanfaat
Private Sub Command1_Click()
'Jika caption command1 "CHECK DATA" maka
If Command1.Caption = "CHECK DATA" Then
Text1.Text = ReadIni("DATA", "Username")
Text2.Text = ReadIni("DATA", "Password")
Command1.Caption = "EDIT"
'Jika caption command1 "EDIT" maka
ElseIf Command1.Caption = "EDIT" Then
Text1 = ""
Text2 = ""
Text1.Enabled = True
Text1.SetFocus
Text2.Enabled = True
Command1.Caption = "SAVE"
'Jika caption command1 "SAVE" maka
ElseIf Command1.Caption = "SAVE" Then
'Pesan Jika text1 dan text2 dalam keadaan kosong dikala di klik command1
If Text1 = "" Or Text2 = "" Then
MsgBox "Please, Complete The Form !", vbInformation, "BLUES PEDIA"
'Jika tidak kosong, maka jadwal akan menyimpan data login
Else
Text1.Text = WriteIni("DATA", "Username", Text1.Text)
Text2.Text = WriteIni("DATA", "Password", Text2.Text)
MsgBox "Data Successfully Changed", vbInformation, "BLUES PEDIA"
Call Form_Load
End If
End If
End Sub
Private Sub Command2_Click()
form2.Hide
form1.Show
form1.Text1 = ""
form1.Text2 = ""
form1.Text1.SetFocus
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text1 = ""
Text2 = ""
Command1.Caption = "CHECK DATA"
End Sub
5. Save program, kemudian buatlah sebuah file txt / notepad dengan nama routerosmikrotik.txt, dan satukan letaknya dengan letak jadwal login ini di simpan, dan tuliskan di file routerosmikrotik.txt'Jika caption command1 "CHECK DATA" maka
If Command1.Caption = "CHECK DATA" Then
Text1.Text = ReadIni("DATA", "Username")
Text2.Text = ReadIni("DATA", "Password")
Command1.Caption = "EDIT"
'Jika caption command1 "EDIT" maka
ElseIf Command1.Caption = "EDIT" Then
Text1 = ""
Text2 = ""
Text1.Enabled = True
Text1.SetFocus
Text2.Enabled = True
Command1.Caption = "SAVE"
'Jika caption command1 "SAVE" maka
ElseIf Command1.Caption = "SAVE" Then
'Pesan Jika text1 dan text2 dalam keadaan kosong dikala di klik command1
If Text1 = "" Or Text2 = "" Then
MsgBox "Please, Complete The Form !", vbInformation, "BLUES PEDIA"
'Jika tidak kosong, maka jadwal akan menyimpan data login
Else
Text1.Text = WriteIni("DATA", "Username", Text1.Text)
Text2.Text = WriteIni("DATA", "Password", Text2.Text)
MsgBox "Data Successfully Changed", vbInformation, "BLUES PEDIA"
Call Form_Load
End If
End If
End Sub
Private Sub Command2_Click()
form2.Hide
form1.Show
form1.Text1 = ""
form1.Text2 = ""
form1.Text1.SetFocus
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text1 = ""
Text2 = ""
Command1.Caption = "CHECK DATA"
End Sub
[DATA]
Username=Routeros Mikrotik
Password=qwerty
Ganti kata Routeros Mikrotik dengan kata untuk login, dan qwerty untuk password
save file
6. Jalankan program
Sekian tutorial kali ini agar bermanfaat
Comments
Post a Comment