vb登录界面编写
VB 登錄界面編寫
登錄界面展示(此篇只有登錄代碼)
登錄代碼
Private Sub Command1_Click() 'command1是登錄的按鈕
Dim no,np, np,np, i%, j%, b%, p%
b = 0
p = 0
If Text1.text = “” Then 'text1是用戶名的label
MsgBox (“請先輸入用戶名!”)
Text1.SetFocus
End If
If Text2.text = “” And Text1.text <> “” Then 'text2是密碼的label
MsgBox (“請輸入密碼!”)
Text2.SetFocus
End If
If Text1.text <> “” And Text2.text <> “” Then
b = 1
End If
If b = 1 Then
Open “” & App.Path & “\save.txt” For Input As #1 '打開存儲用戶名及密碼的文件夾并使用相對路徑 app.path
j = 0
Do While Not EOF(1)
Input #1, no
If Text1.text = no Then
j = 1
Exit Do
End If
Loop
If j = 0 Then
MsgBox (“您還不是已注冊用戶,請先注冊!”)
Text1.text = “”
Text2.text = “”
Else
p = 1
End If
Close #1
Else
End If
If p = 1 Then
Open “” & App.Path & “\pipei.txt” For Input As #1
i = 0
Do While Not EOF(1)
Input #1, np
If Text1.text + Text2.text = np Then
i = 1
Form2.Show
Unload Me
Exit Do
End If
Loop
If i = 0 Then
MsgBox (“密碼錯誤!”)
Text2.text = “”
End If
Close #1
Else
End If
End Sub
Private Sub Command2_Click()
Label5.Caption = “”
Form3.Show
Unload Me
End Sub
Private Sub Form_Load() //設置各個label、command、text的大小
Label1.Left = (Me.ScaleWidth - Label1.Width) \ 2
Label2.Left = (Me.ScaleWidth - 0.8 * Label3.Width) \ 2
Label3.Left = (Me.ScaleWidth - Label3.Width) \ 2
Command1.Left = (Me.ScaleWidth - 2.5 * Command1.Width) \ 2
Command2.Left = (Me.ScaleWidth + 0.5 * Command2.Width) \ 2
Text1.Left = (Me.ScaleWidth - Text2.Width + 500) \ 2
Label5.Left = Text1.Left + 400
Label4.Left = Label2.Left
Text2.Left = Text1.Left
Label7.Left = (Me.ScaleWidth - Label1.Width) \ 2
End Sub
Sub Text1_KeyPress(KeyAscii As Integer)
Dim f%
f = 0
If KeyAscii = 13 Then
If IsNumeric(Text1) Then
Text1.text = “”
MsgBox (“用戶名中不得包含數字!”)
Text1.SetFocus
f = 1
End If
If f = 0 And Text1.text = “” Then
Text1.text = “”
MsgBox (“請輸入用戶名!”)
End If
If f = 0 And Text1.text <> “” Then
Text2.SetFocus
End If
End If
End Sub
Private Sub Text1_LostFocus()
If IsNumeric(Text1) Then
Text1.text = “”
MsgBox (“用戶名中不得包含數字!”)
Text2.SetFocus
End If
End Sub
Private Sub Text2_GotFocus()
If Text1.text = “” Then
Text1.text = “”
MsgBox (“請輸入用戶名!”)
End If
Label5.Caption = “密碼的長度不得超過8位!”
Text2.Locked = False
Text2.PasswordChar = “*”
End Sub
Private Sub Text2_LostFocus()
If Text1.text = “” Then
MsgBox (“密碼錯誤!”)
Text2.text = “”
End If
End Sub
Private Sub Timer1_Timer() //界面展示上有個鬧鐘按鍵 可以顯示當前時間
Timer1.Interval = 1000
End Sub
總結