
VB的Combo中只让输入数值的问题
3个回答
展开全部
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 8 Or KeyAscii = 46 Or (KeyAscii >= 48 And KeyAscii <= 57)) Then
'数字(48-57)或者小数点(46)或者退格(8)
MsgBox "出错"
End If
End Sub
If Not (KeyAscii = 8 Or KeyAscii = 46 Or (KeyAscii >= 48 And KeyAscii <= 57)) Then
'数字(48-57)或者小数点(46)或者退格(8)
MsgBox "出错"
End If
End Sub
展开全部
加个combo box,试试我的代码
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 8 Or KeyCode = 190 Or (KeyCode >= 48 And KeyCode <= 57) Then
'数字(48-57)或者小数点(190)或者退格(8)
Debug.Print KeyCode
Else
MsgBox "出错"
End If
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 8 Or KeyCode = 190 Or (KeyCode >= 48 And KeyCode <= 57) Then
'数字(48-57)或者小数点(190)或者退格(8)
Debug.Print KeyCode
Else
MsgBox "出错"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim temp As String
Private Sub Combo1_KeyPress(KeyAscii As Integer)
temp = Combo1.Text
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Combo1.Text) Then
Debug.Print KeyCode
Else
Combo1.Text = temp
Combo1.SelStart = Len(temp)
Print "wrong"
End If
End Sub
Private Sub Form_Load()
Combo1.Text = "0"
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
temp = Combo1.Text
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Combo1.Text) Then
Debug.Print KeyCode
Else
Combo1.Text = temp
Combo1.SelStart = Len(temp)
Print "wrong"
End If
End Sub
Private Sub Form_Load()
Combo1.Text = "0"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询