Checking for numeric value entered in text box in Visual Basic

前端 未结 6 1304
醉酒成梦
醉酒成梦 2021-01-18 19:21

I am working on a program for my Visual Basic class and have a quick question. One of the things we were encouraged to do was to check to make sure the quantity entered in a

6条回答
  •  误落风尘
    2021-01-18 19:30

    Private Sub txbDwellTime_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txbDwellTime.KeyPress
    
        numDecOnly(e)
    
    End Sub
    
    
    Public Sub numDecOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Or Asc(e.KeyChar) = 46) Then
            'good job do nothing we only allow positive Decimal numbers in this field
            'Asc(e.KeyChar) 48 Through 57 i.e. 0 through 9 Or Asc(e.KeyChar) 46 (dot= .)
        Else
            e.Handled = True
            MsgBox("Only Positive Decimal Numbers Allowed this field")
        End If
    
    End Sub
    

提交回复
热议问题