Results 1 to 11 of 11

Thread: Prevent User input letters.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    Prevent User input letters.

    i have a text box which is suppose to key in decimal or integer..and not letters or commas etc... how do i prevent that?

  2. #2
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220
    How about NumberBox by Martin..

    try this
    http://www.vbforums.com/showthread.p...hreadid=231163
    akki

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    humm..though i dunnno why i cannot open up the exe successfully....Unablr to set the version compatible component...is there other alternatives?

  4. #4
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220
    Ok try this,

    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.    
    3.     If (KeyAscii < 48 Or KeyAscii > 57) And NotDecimal(KeyAscii) And KeyAscii <> 8 Then
    4.         KeyAscii = 0
    5.     End If
    6.    
    7. End Sub
    8.  
    9. Private Function NotDecimal(KeyAscii As Integer) As Boolean
    10.     If KeyAscii <> 46 Or InStr(1, Text1.Text, ".") > 0 Then
    11.         NotDecimal = True
    12.     Else
    13.         NotDecimal = False
    14.     End If
    15. End Function
    Last edited by akki; Feb 13th, 2004 at 01:15 AM.
    akki

  5. #5
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476
    Or Try this
    VB Code:
    1. Public Function CheckNoAlphas(KeyAscii As Integer, Optional Existing As String, Optional SelStart As Integer) As Integer
    2. On Error Resume Next
    3.     'allow control keys through
    4.     If KeyAscii = vbKeyReturn Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeyEscape Or KeyAscii = vbKeyBack Then
    5.         CheckNoAlphas = KeyAscii
    6.         Exit Function
    7.     End If
    8.    
    9.     'block non numerics
    10.     If Not IsNumeric(Chr(KeyAscii)) Then
    11.         KeyAscii = 0
    12.         MsgBox "Enter numbers only", , "Numbers Only"
    13.     Else
    14.         CheckNoAlphas = KeyAscii
    15.     End If
    16. End Function
    I call it from the keyPress event.
    The problem you need to solve is allowing decimals and delete key strokes

    Good Luck

    FW

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    hey thanks to you all...your code works fine....(akki)
    however cuz i have 'force' user to key in something in the txtboxes.... : if txtboxes.text= " " then
    MsgBox "xxxx"
    Exit Sub
    ....

    however i dunno why suddenly all the Sub auto change to Function....and erors pop out....

  7. #7
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220
    mhhh.... could not get your error correctly.... where r u checking if txtboxes.text= " " ?

    Posting your code may help !!
    akki

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    the checking is done on a click button where the values from the txtbox is extracted and manipulaiton calculation.......is abit long for the codes...cuz there are many txtboxs actually...and different combinations...sorrie..abt that

  9. #9
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220
    is "txtboxes" name of your textbox? is it a control array?
    akki

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    yup txtbox.text is the name of the textbox

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Those wont work with right click>paste

    Have to rush right now...

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