用户名验证程序,能不能帮我简化一点

来源:百度知道 编辑:UC知道 时间:2024/09/23 14:30:43
这是我写的小程序,我觉得不好,只能实现一点功能,请各位指教一下,帮简化一点,或者错误

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

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