注册 登录
编程论坛 VB6论坛

文本框输入限制,无法清空文本框,帮忙看看错在哪?

wxflw 发布于 2012-02-13 15:07, 1294 次点击
Private Sub Text3_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text3.SelStart = aword
  Case Else
    MsgBox ("密码只能为英文字母或者阿拉伯数字")
    Text3.Text = ""          ,《《-----------这句没效果
    Text3.SetFocus
End Select
End Sub

该怎么弄?请指教啊,在线等
12 回复
#2
zhuyongxing2012-02-13 19:38
Private Sub Text3_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text3.SelStart = aword
  Case Else
    KeyAscii = 0
    MsgBox ("密码只能为英文字母或者阿拉伯数字")
   
    'Text3.Text = ""          '《《-----------这句没效果
    Text3.SetFocus
End Select
End Sub
#3
zhuyongxing2012-02-13 19:39
Private Sub Text3_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text3.SelStart = aword
  Case Else
    KeyAscii = 0
    MsgBox ("密码只能为英文字母或者阿拉伯数字")
   
    Text3.Text = ""          '《《-----------这句没效果
    Text3.SetFocus
End Select
End Sub
'这是清空效果
#4
Artless2012-02-13 23:22
以下是引用zhuyongxing在2012-2-13 19:39:33的发言:

Private Sub Text3_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text3.SelStart = aword
  Case Else
    KeyAscii = 0
    MsgBox ("密码只能为英文字母或者阿拉伯数字")
   
    Text3.Text = ""          '《《-----------这句没效果
    Text3.SetFocus
End Select
End Sub
'这是清空效果

清空干嘛?
#5
wxflw2012-02-14 12:14
是这样的!我想限制不能输入中文,如果是中文弹出提示,点确定后清空输入内容,要不然,虽然有提示,但是输入的中文还是或保留在TXET文本框中,因为是密码输入框所以。。。。。
如果有限制中文输入的代码,希望能发个来看看!!谢谢
#6
yiyaozjk2012-02-14 15:06
我单独把你的代码放我的电脑上测试了一下,应该是可以清空的.

不知道你这个Text3还有没有其它代码限制,比如Text3__LostFocus()之类的,反而不清空了///要找上下环境去找原因....
#7
wxflw2012-02-14 19:27
没有其他的了我吧所有的代码发上来
Private Sub Command1_Click()
If Text1.Text = "" Then
    MsgBox "请您输入查询条件", 32, "系统"
     Exit Sub
Else
    = adCmdText
   Adodc1.RecordSource = "select * from [user] where  用户名 = '" & Trim(Text1.Text) & "'"
   Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
   Text2.Text = Adodc1.Recordset.Fields("用户名")
   Text3.Text = Adodc1.Recordset.Fields("密码")
   Combo1.Text = Adodc1.Recordset.Fields("权限")
   Text1.Text = ""
   Text2.Enabled = False
   Text3.Enabled = False
   Combo1.Enabled = False
   Command3.Enabled = True
Else
    MsgBox "没有您要查找的员工,请您确认后重新输入", 32, "系统"
   End If
   End If
End Sub

Private Sub Command2_Click()
Command3.Enabled = False
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text4.Enabled = True
Combo1.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text2.BackColor = &H80000005
Text3.BackColor = &H80000005
Text4.BackColor = &H80000005
Combo1.BackColor = &H80000005
Combo1.Text = "业务员"
End Sub
Private Sub Command3_Click()
Text2.Enabled = True
Text3.Enabled = True
Combo1.Enabled = True
Text2.BackColor = &H80000005
Text3.BackColor = &H80000005
Combo1.BackColor = &H80000005
End Sub

Private Sub Command4_Click()
    If Text2.Text = "" Then
     MsgBox "姓名不能为空!", 32, "系统"
     Exit Sub
    Else
    End If
   If Text3.Text = "" Then
   MsgBox "密码不能为空!", 32, "系统"
     Exit Sub
    Else
    End If
   If Text4.Text = "" Then
   MsgBox "请再次输入密码!", 32, "系统"
   Text4.SetFocus
     Exit Sub
    Else
    End If
   If Text4.Text <> Text3.Text Then
   MsgBox "两次密码输入不一致,请重新输入!", 32, "系统"
   Text4.Text = ""
   Text4.SetFocus
    Exit Sub
    Else
    End If
   If Combo1.Text = "业务员" Then
   GoTo zx
   Else
   End If
   If Combo1.Text = "管理员" Then
   GoTo zx
   Else
   MsgBox "权限只能为“业务员”或“管理员”!", 32, "系统"
   Exit Sub
   End If
zx:
    = adCmdText
    Adodc1.RecordSource = "select * from [user] where  用户名 = '" & Trim(Text2.Text) & "'"
    Adodc1.Refresh
   If Adodc1.Recordset.RecordCount > 0 Then
      myval = MsgBox("已有此人员记录!按确认键修改记录,否则请重新输入!", vbYesNo, "系统")
   If myval = vbYes Then
     Adodc1.Recordset.Fields("用户名") = Trim(Text2.Text)
     Adodc1.Recordset.Fields("密码") = Trim(Text3.Text)
     Adodc1.Recordset.Fields("权限") = Trim(Combo1.Text)
     Adodc1.Recordset.Update
     MsgBox "数据修改成功!", , "系统提示"
     Adodc1.Refresh
  Exit Sub
  End If
  Else
    Adodc1.Recordset.AddNew
    Adodc1.Recordset.Fields("用户名") = Trim(Text2.Text)
    Adodc1.Recordset.Fields("密码") = Trim(Text3.Text)
    Adodc1.Recordset.Fields("权限") = Trim(Combo1.Text)
    Adodc1.Recordset.Update
    Adodc1.Recordset.Close
    MsgBox "数据保存成功!", , "系统提示"
    Adodc1.Refresh
End If
Call Form_Load
End Sub

Private Sub Command5_Click()
Form3.Show
Unload Me
End Sub
Private Sub Command6_Click()
Call Form_Load
End Sub
Private Sub Command7_Click()
If Text2.Text = "" Then
  MsgBox "请查找是否有此记录!", , "系统提示"
  Exit Sub
  End If
If Text2.Text <> "" Then
    = adCmdText
   Adodc1.RecordSource = "select * from [user] where  用户名 = '" & Trim(Text2.Text) & "'and 权限 = '" & Trim(Combo1.Text) & "'"
   Adodc1.Refresh
 If Adodc1.Recordset.RecordCount > 0 Then
   myval = MsgBox("确定删除此用户吗?", vbYesNo, "系统")
  If myval = vbYes Then
   Adodc1.Recordset.Delete
   Adodc1.Refresh
   End If
    MsgBox "删除成功!", , "系统提示"
   Call Form_Load
   End If
   Else
   MsgBox "请查找是否有此记录!", , "系统提示"
   End If
End Sub
Private Sub Form_Load()
Command3.Enabled = False
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text2.Enabled = False
Text2.BackColor = &HFFFFC0
Text3.Enabled = False
Text3.BackColor = &HFFFFC0
Text4.Enabled = False
Combo1.Enabled = False
Combo1.BackColor = &HFFFFC0
Text4.BackColor = &H0&
Combo1.Text = ""
Combo1.AddItem "业务员"
Combo1.AddItem "管理员"
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text3.SelStart = aword
  Case Else
     MsgBox ("密码只能为英文字母或者阿拉伯数字")
Text3.Text = ""
Text3.SetFocus
End Select
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
aword = aword + 1
If KeyAscii = 8 Then Exit Sub
Select Case Chr(KeyAscii)
  Case "a" To "z", "A" To "Z", "0" To "9"
    Text4.SelStart = aword
  Case Else
     MsgBox ("密码只能为英文字母或者阿拉伯数字")
    Text4.Text = ""
    Text4.SetFocus
只有本站会员才能查看附件,请 登录

End Select
End Sub
#8
yiyaozjk2012-02-14 19:56
仔细看了一下:

Private Sub Command1_Click()
....
If Adodc1.Recordset.RecordCount > 0 Then
   Text2.Text = Adodc1.Recordset.Fields("用户名")
   Text3.Text = Adodc1.Recordset.Fields("密码")
   Combo1.Text = Adodc1.Recordset.Fields("权限")
   Text1.Text = ""
   Text2.Enabled = False
   Text3.Enabled = False

   你这里不有过一句话 Text3.Enabled = False 不是不能更改吗??????
   根据我猜测:你可能在查找到了一个人之后,再去修改了吗?此时当然不能清空的了......不知我猜的对不对?

   

#9
wxflw2012-02-15 11:29
我在点击添加以后,也就是
Private Sub Command2_Click()
中把
Text3.Enabled = False
改成了
Text3.Enabled = ture
就是说
Text3.Enabled 已经可以更改了


[ 本帖最后由 wxflw 于 2012-2-15 11:32 编辑 ]
#10
yiyaozjk2012-02-15 14:49
问题是:
你把添加和查找\修改 都放到了一个界面了,如果你先去查找呢再去修改呢? 或者 添加后,再点击了修改呢??? 结果呢???
#11
lowxiong2012-02-15 14:58
这代码写的,连goto都出来了。自从知道结构化后,我写代码就从没出现过goto语句。
如果仅仅只需要文本框不能输入汉字的话,其实只需修改text3和text4的imemode属性为3-disable,即可让文本框无论如何都不能通过键盘都输入汉字(拷贝粘贴除外),如果是用作密码的,只需要将text3、text4的passwoedchar属性里输入一个字符(通常是*)即可。
#12
wxflw2012-02-16 16:52
添加按钮是初始化text等信息输入框的,没有写入数据库的功能,只有点击保存才能写入数据库
如果已经有登记过的用户名会弹出提示,已经存在该用户,如果确定保存只是修改该用户的信息,不会删除该用户,也不会
重复添加该用户。我考虑过这个问题过了,所以在保存按钮里有判断语句了的。
#13
JayBeenLiang2012-02-23 20:53
新手上路还要,还要好好学习,上面的代码很多看不懂啊
1