19 November 2012

Check Input Value 0 To 4 in VB.Net

 Dim chk As Boolean
    Function IsChekcInputValue(ByVal number As Double) As Boolean
        If number = 0 Or number = 1 Or number = 2 Or number = 3 Or number = 4 Then
            Return True
            Return False
        End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For I As Integer = 0 To Trim(TextBox1.Text.Length) 
            chk = IsChekcInputValue(TextBox1.Text.IndexOf(I))
        If chk = False Then
            MsgBox("Please Enter 0 To 4 Numbers in Input Box")
            MsgBox("Thank U")
        End If
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Char.IsNumber(e.KeyChar) = False Then
            e.Handled = True
        End If
    End Sub

No comments: