Results 1 to 5 of 5

Thread: Simple Is numeric statement :mad:

  1. #1

    Thread Starter
    Member ThePCMan's Avatar
    Join Date
    Dec 2004
    Location
    Aylesbury, UK
    Posts
    33

    Simple Is numeric statement :mad:

    Hi guys,

    Want 2 know some simple code for stopping alphabetical data being entered into a textbox. And allowing numerical data

    Got any ideas, my last try was:


    VB Code:
    1. Private Sub txtContactno_KeyPress(KeyAscii As Integer)
    2.     If IsNumeric(Chr(KeyAscii)) Then    ' For some reason this doesn't work
    3.         KeyAscii = 0
    4.     End If
    5. End Sub

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Pakistan
    Posts
    436

    Re: Simple Is numeric statement :mad:

    You need to pass two parmameters first one is "keyascii" and second is textbox name

    VB Code:
    1. Public Sub OnlyNumeric(ByRef KeyAscii As Integer, Txt As TextBox)
    2.         Select Case KeyAscii
    3.             Case 48 To 57
    4.                 IntPosition = InStr(1, Txt.Text, ".")
    5.                 If IntPosition > 0 Then
    6.                     If Len(Txt.Text) - InStr(1, Txt, ".") = 4 Then
    7.                         KeyAscii = 0
    8.                     Else
    9.                         KeyAscii = KeyAscii
    10.                     End If
    11.                 End If
    12.             Case 8
    13.             Case 46
    14.                     If InStr(1, Txt, ".") Then
    15.                         KeyAscii = 0
    16.                     Else
    17.                         KeyAscii = KeyAscii
    18.                     End If
    19.                
    20.             Case 45
    21.                    
    22.                     If InStr(1, Txt.Text, "-") Then
    23.                         KeyAscii = KeyAscii
    24.                     Else
    25.                         KeyAscii = 0
    26.                     End If
    27.             Case Else
    28.                 KeyAscii = 0
    29.             End Select
    30. End Sub

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Simple Is numeric statement :mad:

    Quote Originally Posted by ThePCMan
    Hi guys,

    Want 2 know some simple code for stopping alphabetical data being entered into a textbox. And allowing numerical data

    Got any ideas, my last try was:


    VB Code:
    1. Private Sub txtContactno_KeyPress(KeyAscii As Integer)
    2.  
    3.  
    4. End Sub
    the above code is backwards, it stops numerics
    try
    VB Code:
    1. If Not IsNumeric(Chr(KeyAscii)) Then
    2.         KeyAscii = 0
    3.     End If

    rgds pete

  4. #4

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Pakistan
    Posts
    436

    Re: Simple Is numeric statement :mad:

    Dear Martin

    Ya it is true, said codes are belong to your control exactally, but it is clear in my mind only to help some one and i hav't the reference of these code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width