1   1  /  1  页   跳转

VB一小问题..

VB一小问题..

VB  .
假设个  文本控件..

用什么代码能限制里面只能输入 <9位的数字(不包括中文)..

有空的大虾麻烦发下代码..


[用户系统信息]Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
最后编辑2007-10-14 20:13:17
分享到:
gototop
 

在chang事件里判断输入是否为数字,如果不是报错。在属性里有一个限定字符最大长度的属性,相信应该很好找!
gototop
 

Private Sub Form_Activate()
Text1.SetFocus
End Sub

Private Sub Form_Load()
Text1.Text = ""
Text1.MaxLength = 9
End Sub

Private Sub Text1_Change()
If (Right(Text1.Text, 1) < "0" Or Right(Text1.Text, 1) > "9") And Text1.Text <> "" Then
    MsgBox "请输入0—9的数字!"
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    Text1.SelStart = Len(Text1.Text)
End If
End Sub

界面拉个文本框(text)就行
gototop
 

谢谢.
回家试下..

还有..

您真的只是个小学生?..

- -.
gototop
 

限制数字输入可以在按键输入事件中判断ASCII码是否是数字更好点。
gototop
 

Private Sub Form_Load
    Text1.MaxLength = 9
End Sub
Private Sub Text1_Change()
    Text1.Text=val(Text1.text)
End Sub
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT