Results 1 to 10 of 10

Thread: VB - Numeric Textbox input only

Threaded View

  1. #1

    Thread Starter
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Resolved VB - Numeric Textbox input only

    As you type the text

    VB Code:
    1. Private Sub Textbox1_KeyPress(index As Integer, KeyAscii As Integer)
    2. 'Accepts only numeric input
    3. Select Case KeyAscii
    4.   Case vbKey0 To vbKey9
    5.   Case vbKeyBack, vbKeyClear, vbKeyDelete
    6.   Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown, vbKeyTab
    7.   Case Else
    8.     KeyAscii = 0
    9.     Beep
    10. End Select
    11. End Sub
    Clicking a command button to validate

    VB Code:
    1. Private Sub Command1_Click()
    2.     If Not IsNumeric(Text1.Text) Then
    3.         MsgBox "Please enter numbers only.", vbInformation
    4.         'you may also consider erasing it
    5.         Text1.Text = ""
    6.     End If
    7. End Sub
    Last edited by x-ice; Dec 14th, 2006 at 01:18 PM.

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