vb高手,帮我看下,这程序运行时出现对话框,我应该输入的用户名及密码格式是什么样的,给个具体的例子 5
OptionExplicitPrivatestrSQLAsStringPrivatestrMsgTextAsStringPrivateSubcmdOK_Click()Di...
Option Explicit
Private strSQL As String
Private strMsgText As String
Private Sub cmdOK_Click()
Dim i As Integer
Dim j As Integer
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'用户添加输入设置合法性判断
If Trim(txtNewUser(0).Text) = "" Then
MsgBox "用户名不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) = "" Then
MsgBox "密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(1).SetFocus
Exit Sub
End If
If Trim(txtNewUser(2).Text) = "" Then
MsgBox "确认密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) <> Trim(txtNewUser(2).Text) Then
MsgBox "确认密码不正确!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
'查询用户是否存在
strSQL = "select * from Users where UserName='" & Trim(txtNewUser(0).Text) & "'"
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果用户存在
If objRecordset.EOF = False Then
MsgBox " 已存在该用户!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
txtNewUser(0).SelStart = 0
txtNewUser(0).SelLength = Len(txtNewUser(0).Text)
Exit Sub
End If
'如果用户不存在,添加新用户
strSQL = "select * from Users"
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
objRecordset.AddNew
objRecordset.Fields(0) = Trim(txtNewUser(0).Text)
objRecordset.Fields(1) = Trim(txtNewUser(1).Text)
'更新用户数据库
objRecordset.Update
'添加
MsgBox " 用户添加成功!", vbExclamation + vbOKOnly, "提示"
txtNewUser(0).Text = ""
txtNewUser(1).Text = ""
txtNewUser(2).Text = ""
End Sub
'取消
Private Sub cmdCancel_Click()
Unload Me
End Sub 展开
Private strSQL As String
Private strMsgText As String
Private Sub cmdOK_Click()
Dim i As Integer
Dim j As Integer
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'用户添加输入设置合法性判断
If Trim(txtNewUser(0).Text) = "" Then
MsgBox "用户名不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) = "" Then
MsgBox "密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(1).SetFocus
Exit Sub
End If
If Trim(txtNewUser(2).Text) = "" Then
MsgBox "确认密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) <> Trim(txtNewUser(2).Text) Then
MsgBox "确认密码不正确!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
'查询用户是否存在
strSQL = "select * from Users where UserName='" & Trim(txtNewUser(0).Text) & "'"
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果用户存在
If objRecordset.EOF = False Then
MsgBox " 已存在该用户!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
txtNewUser(0).SelStart = 0
txtNewUser(0).SelLength = Len(txtNewUser(0).Text)
Exit Sub
End If
'如果用户不存在,添加新用户
strSQL = "select * from Users"
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
objRecordset.AddNew
objRecordset.Fields(0) = Trim(txtNewUser(0).Text)
objRecordset.Fields(1) = Trim(txtNewUser(1).Text)
'更新用户数据库
objRecordset.Update
'添加
MsgBox " 用户添加成功!", vbExclamation + vbOKOnly, "提示"
txtNewUser(0).Text = ""
txtNewUser(1).Text = ""
txtNewUser(2).Text = ""
End Sub
'取消
Private Sub cmdCancel_Click()
Unload Me
End Sub 展开
展开全部
仅从代码上来看,可知道:
txtNewUser(0) 里填用户名
txtNewUser(1) 里填密码
txtNewUser(2) 里填确认密码
这三个文本框里的内容都没有限制字符的长度,只要字符不为空就行,还有,程序会将这三个文本框里字符首尾的空格删除.所有,只要注意这些就行了,
txtNewUser(0) 里填用户名
txtNewUser(1) 里填密码
txtNewUser(2) 里填确认密码
这三个文本框里的内容都没有限制字符的长度,只要字符不为空就行,还有,程序会将这三个文本框里字符首尾的空格删除.所有,只要注意这些就行了,
更多追问追答
追问
可是当我在对话框里面随便输入时,比方说输入用户:123,密码:456,确认密码:456,就会出现用户类型未定义的错误
追答
你看一下是哪一句出的错误?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询