VB编程,在密码登陆框中,当用户输入用户名错误的时候,怎么让用户重新输入用户名和限制仅输入三次即退出运行
问题即使问题标题本身:下边是代码:DimusernameAsStringPrivateSubForm_Load()username=InputBox$("请输入你的用户名...
问题即使问题标题本身:
下边是代码:
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 展开
下边是代码:
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 展开
5个回答
展开全部
dim i as integer
for i=0 to 2
"显示输入密码对话框和验证密码的代码"
"如果密码正确
exit for"
next i
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 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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这样试试看吧!
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
看看行不行,还有下次编程注意美观!
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
看看行不行,还有下次编程注意美观!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询