vb登录界面编写

VB 登录界面编写

登录界面展示(此篇只有登录代码)
登录界面展示
登录代码
Private Sub Command1_Click() 'command1是登录的按钮
Dim no , n p , 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

**label7.Caption =now()**

End Sub

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱编程的小黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值