Only allow numeric values in the textbox

前端 未结 12 1028
南笙
南笙 2021-01-12 03:53

I want to make a TextBox control that only accepts numerical values.

How can I do this in VB6?

12条回答
  •  醉话见心
    2021-01-12 04:11

    The following may be used for whole numbers:

    Private Sub text1_KeyPress(KeyAscii As Integer)
        If Not IsNumeric(text1.Text & Chr(KeyAscii)) And Not KeyAscii = 8 Then    KeyAscii = 0
        if (KeyAscii>=43) and (KeyAscii<=46) Then KeyAscii = 0 
        'it ignores '-', '+', '.' and ','
    End Sub
    

提交回复
热议问题