2017年食堂外包信息:VB编程,在密码登陆框中,当用户输入用户名错误的时候,怎么让用户重新输入用户名和限制仅输入三次即退出运行

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 04:39:27
问题即使问题标题本身:
下边是代码:
Dim username As String
Private Sub Form_Load()
username = InputBox$("请输入你的用户名!", "身份验证框")
Dim usernames(3) As String '定义一个用户名数组
usernames(0) = "xiaoc"
usernames(1) = "xiaoq"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"
Dim flag As Boolean '定义flag为逻辑型
Dim i As Integer
flag = False
For i = 0 To 3
If username = usernames(i) Then
flag = True
End If
Next i
If flag = False Then
MsgBox ("用户确认失败,退出系统!") '如果输入用户名 错误,退出系统
End
End If
End Sub

Private Sub Picture1_Paint()
Picture1.Print " you are welcome!" & username '在图片框中输出欢迎语句和用户名,注意,这个用户名要在通用中声明,不然用户名显示不出来的
End Sub

在用户确认和退出系统之间加个计数,满3次则end,不满3次则回到输入用户名那一段代码。

dim i as integer
for i=0 to 2
"显示输入密码对话框和验证密码的代码"
"如果密码正确
exit for"
next i

用goto做的
可以使用,但不一定是最好的~

Dim username As String
dim Num as Integer
Private Sub Form_Load()

Dim usernames(3) As String '定义一个用户名数组
usernames(0) = "xiaoc"
usernames(1) = "xiaoq"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"
Dim flag As Boolean '定义flag为逻辑型
Dim i As Integer
flag = False

xzp:
username = InputBox$("请输入你的用户名!", "身份验证框")

For i = 0 To 3
If username = usernames(i) Then
flag = True
End If
Next i
If flag = False Then
MsgBox ("用户确认失败,退出系统!") '如果输入用户名 错误,退出系统
if num<3 then
num=num+1
goto xzp
else
End
end if
End If
End Sub

这样试试看吧!
Dim username As String
Dim j As Integer
Private Sub Form_Load()

Static j

j = 0
satr:

username = InputBox$("请输入你的用户名!", "身份验证框")
Dim usernames(3) As String '定义一个用户名数组
usernames(0) = "xiaoc"
usernames(1) = "xiaoq"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"
Dim flag As Boolean '定义flag为逻辑型
Dim i As Integer
flag = False
For i = 0 To 3
If username = usernames(i) Then
flag = True
End If
Next i
If flag = False Then
MsgBox ("用户确认失败,退出系统!") '如果输入用户名 错误,退出系统
j = j + 1
If j = 3 Then
End
Else
GoTo satr
End If

End
End If
End Sub

Private Sub Picture1_Paint()
Picture1.Print " you are welcome!" & username '在图片框中输出欢迎语句和用户名,注意,这个用户名要在通用中声明,不然用户名显示不出来的
End Sub

看看行不行,还有下次编程注意美观!

Private Sub Form_Load()
s = "请输入你的用户名!"
Do
user = InputBox$(s, "身份验证框")
For i = 0 To 3
If user = Array("xiaoc", "xiaoq", "xiaol", "xiaoz")(i) Then
Exit Do
Else
s = "用户确认失败!请再输入你的用户名!"
End If
Next
n = n + 1
Loop Until n = 3
If n = 3 Then
MsgBox "用户确认失败,退出系统!"
End
End If
Picture1.Print " you are welcome!"
Picture1.Print Tab(5); user & "!!!!"
End Sub