我是初学者,我在做一个登陆界面,要求不能是非数字型用户名。我做2中都有缺陷。
第一种,是用循环只要输入非数字他都会应为字符的长度循环6次。
Private Sub Command1_Click()
Dim i As String, a As String, b As String
Dim str1 As String, c As Integer
str1 = Text1.Text
For c = 1 To Len(str1)
If Not IsNumeric(Mid(str1, c, 1)) Then
i = MsgBox("帐号中出现非数字字符" + Chr(13) + Chr(10) + "请重新输入!", 0 + 16 + 0, "输入帐号")
End If
Next c
a = (Text1.Text)
b = (Text2.Text)
If a <> "123456" Then
i = MsgBox("帐号错误" + Chr(13) + Chr(10) + "请重新输入", 1 + 16 + 0, "请输入帐号")
Text1.Text = ""
Text1.SetFocus
ElseIf b <> "vb6" Then
i = MsgBox("密码错误", 1 + 48 + 0, "请输入密码")
Text2.Text = ""
Text2.SetFocus
ElseIf a = "123456" And b = "vb6" Then
Form1.Hide
Form2.Show
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Text1_Change()
Text1.MaxLength = 6
End Sub
Private Sub Text2_Change()
Text2.MaxLength = 4
Text2.PasswordChar = "*"
End Sub
第二种,不管输入数字还是非数字都要经过第一段程序,而且帐号密码都对都进不去。
Private Sub Command1_Click()
Dim i As String, a As String, b As String
Dim str1 As String, c As Integer
Dim d As Boolean
If Not IsNumeric(d) = False Then
i = MsgBox("帐号中出现非数字字符" + Chr(13) + Chr(10) + "请重新输入!", 0 + 16 + 0, "输入帐号")
Text1.Text = ""
End If
a = (Text1.Text)
b = (Text2.Text)
If a <> "123456" Then
i = MsgBox("帐号错误" + Chr(13) + Chr(10) + "请重新输入", 1 + 16 + 0, "请输入帐号")
Text1.Text = ""
Text1.SetFocus
ElseIf b <> "vb6" Then
i = MsgBox("密码错误", 1 + 48 + 0, "请输入密码")
Text2.Text = ""
Text2.SetFocus
ElseIf a = "123456" And b = "vb6" Then
Form1.Hide
Form2.Show
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Text1_Change()
Text1.MaxLength = 6
End Sub
Private Sub Text2_Change()
Text2.MaxLength = 4
Text2.PasswordChar = "*"
End Sub
请高手指点,请说详细一点,我是新手好多都不太懂。