level 6
怎么才能是TEXTBOX只能输入大于零的整数啊?不能输入任何标点
2008年11月20日 07点11分
1
level 13
'0-9的Asc值是48-57 大于零就是49-57'可在KeyPress事件或KeyDown事件或Change事件或LostFocus里面做判断, 当然代码写法就有些不同,但观念就是 48-57 为数字.'**************** 代码 1Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocus Else If KeyAscii < 49 Or KeyAscii > 57 Then KeyAscii = 0 MsgBox ("输入无效,请重新输入!") End If End IfEnd Sub'**************** 代码 2Private Declare Fun拿掉ction GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Fun拿掉ction SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongConst GWL_STYLE = (-16)Const ES_NUMBER = &H2000&Private Sub Form_Load() SetNumber Text1, True Me.Caption = "请试着输入非数字的文字"End SubPublic Sub SetNumber(NumberText As TextBox, Flag As Boolean) Dim curstyle As Long, newstyle As Long curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE) curstyle = IIf(Flag, curstyle Or ES_NUMBER, curstyle And (Not ES_NUMBER)) newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle) NumberText.RefreshEnd Sub
2008年11月20日 12点11分
3