电视剧北方往事10集:用户名验证程序,能不能帮我简化一点

来源:百度文库 编辑:中科新闻网 时间:2024/04/30 06:01:57
这是我写的小程序,我觉得不好,只能实现一点功能,请各位指教一下,帮简化一点,或者错误

Dim username As String
Dim flag As Boolean
Private Sub Form_Activate()
Picture1.Print " you are welcome!"
Picture1.Print Tab(5); username & "!!!!" '输出欢迎信息
End Sub

Private Sub Form_Load()
username = InputBox$("请输入你的用户名!", "身份验证框")
Dim usernames(3) As String '定义一个数组
usernames(0) = "xiaoc"
usernames(1) = "xiaoq"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"

Dim i As Integer, j As Integer
flag = False
For i = 0 To 3 '判定第一次输入是否正确
If username = usernames(i) Then
flag = True
Exit For
End If
Next i
If flag = False Then '判定第二、三次输入是否正确
For j = 1 To 2
username = InputBox$("用户确认失败!请再输入你的用户名!", "身份验证框")
For i = 0 To 3
If username = usernames(i) Then
flag = True
Exit For
End If
Next i
If flag = True Then
Exit For
End If
Next j
End If
If flag = False Then
MsgBox ("用户确认失败,退出系统!") '如果不正确就退出
End
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
Print " you are welcome!"
Print Tab(5); user & "!!!!"
End Sub