VB简单问题,来个人帮忙回答一下,谢谢

来源:百度知道 编辑:UC知道 时间:2024/07/07 07:07:01
两个问题哈
1 在textbox中只可以输入数字
2 输入的字符长度不超过6时始终有焦点,等于6时失去焦点

Private Sub Text1_Change()
If Len(Text1) = 6 Then Text2.SetFocus '让text1失去焦点,并且让别人有焦点,所以此处是让text2得到焦点,注意你的程序得有这个控件.
Text1 = Left(Text1, 6)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not Chr(KeyAscii) Like "[0-9]" Then KeyAscii = 0
End Sub

Private Sub Text1_LostFocus()
If Len(Text1) < 6 Then Text1.SetFocus
End Sub