dcsimg
Results 1 to 8 of 8

Thread: Numeric Value Only in textbox

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,725

    Numeric Value Only in textbox

    Hi! I would like to share what I have created. It just a simple could that will limit the textbox entry to numbers only.

    The code is in a module so you can reuse it. BTW, it also allows you to use period(.) and negative(-). You are limited to use only one negative sign and can only be put before any number.

    I have not included enter key in the module instead it is done in the keypress event of textbox.

    Please leave me some reputation if you like this code!

    Code edited: Now right click and paste is disabled
    Attached Files Attached Files
    Last edited by Simply Me; May 28th, 2006 at 08:40 AM. Reason: Right Click and Paste added
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Numeric Value Only in textbox

    you can still paste in non-numeric characters from the context menu...

  3. #3

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,725

    Re: Numeric Value Only in textbox

    Yes that's true. I have not take cared of it yet and also the formatting of number such as when the user type 12 it will not make it as 12.00.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  4. #4

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,725

    Re: Numeric Value Only in textbox

    Code is already edited. I have disabled right click and paste.

    Why is it that the number of views in my attachment was reset to zero?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Numeric Value Only in textbox

    because it's a different attachment

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Numeric Value Only in textbox

    There's still a problem with your code. You used MouseDown event to disable right mouse click. So. Click on any TextBox with right mouse button and hold it, then press ENTER to supress the MsgBox, and release mouse button you're holding

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Numeric Value Only in textbox

    Plus you can still use Shift+Insert to paste. And you could set text by SendMessage if you really want to be picky


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Hyperactive Member nepalbinod's Avatar
    Join Date
    Sep 2007
    Posts
    293

    Re: Numeric Value Only in textbox

    'Call the function Ut_IntegerValidation on any textbox or control which has .text property

    Private Sub Text1_Change()
    Ut_IntegerValidation Text1
    End Sub



    'Paste the following code in a module
    Public Function Ut_IntegerValidation(ByVal MyTextBox As Control)

    If Not IsNumeric(MyTextBox.Text) Then
    MyTextBox.Text = ""
    ElseIf IsNumeric(MyTextBox.Text) Then
    If Val(MyTextBox.Text) < 0 Then
    MyTextBox.Text = ""
    End If
    End If


    End Function

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width