2007/05/26
VB中的EOF SETFOCUS是什么意思!
问题:
Private Sub Command1_Click()
Dim sql As String
Dim rs_add As New ADODB.Recordset
If Trim(Text1.Text) = "" Then
MsgBox "用 户名不能为空", vbOKOnly + vbExclamation, ""
Exit Sub
Text1.SetFocus
Else
If Trim(Text2.Text) = "" Then
MsgBox "密码不能为空", vbOKOnly + vbExclamation, ""
Exit Sub
Text2.SetFocus
Else
sql = "select * from 系统管理"
rs_add.Open sql, conn, adOpenKeyset, adLockPessimistic
While (rs_add.EOF = False)
If Trim(rs_add.Fields(0)) = Trim(Text1.Text) Then
MsgBox "已有这个用户", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
Exit Sub
Else
rs_add.MoveNext
End If
Wend
If Trim(Text2.Text) <> Trim(Text3.Text) Then
MsgBox "两次密码不一致", vbOKOnly + vbExclamation, ""
Text2.SetFocus
Text2.Text = ""
Text3.Text = ""
Exit Sub
ElseIf Trim(Combo1.Text) <> "system" And Trim(Combo1.Text) <> "guest" Then
MsgBox "请选择正确的用户权限", vbOKOnly + vbExclamation, ""
Combo1.SetFocus
Combo1.Text = ""
Exit Sub
Else
rs_add.AddNew
rs_add.Fields(0) = Text1.Text
rs_add.Fields(1) = Text2.Text
rs_add.Fields(2) = Combo1.Text
rs_add.Update
rs_add.Close
MsgBox "添加用户成功", vbOKOnly + vbExclamation, ""
Unload Me
End If
End If
End If
End Sub
解释:
EOF就是记录的最后一条
setfocus是把焦点指向一个控件
补充,就拿你这个来说,While (rs_add.EOF = False) 也就是说如果不到记录的最后一条就一直循环。
Text1.SetFocus 也说是说当这个用户已经存在时,把光标定位在Text1中
No comments yet