Results 1 to 6 of 6

Thread: Need some help on validating input

  1. #1

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's my dillema, i have a text box which must hold 8 numbers, no letters, and when enter is pressed, it calls a command_click event. I can't use the max length property because some of the numbers that i'm pulling from a database are over 8 characters, and i need to go in and edit them all. I can't figure out how to implement this?? Thanks

  2. #2
    Addicted Member overhill's Avatar
    Join Date
    Mar 2000
    Location
    KS, United States
    Posts
    181

    Question

    What are you trying to use the MaxLength property for? Are you needing help calling the Command_click event? Do you want to check to see if all of the characters in the textbox are numbers? I guess that I just need you to explain what exactly you need help with.

  3. #3
    Guest
    on keypress event

    if not isnumeric(chr(keyascii)) _
    and keysacii <> vbkeyreturn and len(text1)> 7 then
    keyascii = 0
    end if
    if keyascii = vbkeyreturn then
    call command_click
    end if

    this will allow your textbox to accept upto 8 numbers only.

  4. #4

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I tried that last response, it allows letters to be entered, and also more than 8 numbers can be entered. Anyone else with some ideas.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Private Sub Form_Load()
        Text1.Tag = "00000000"
        Text1.Text = "00000000"
    End Sub
    'or maybe you just change those properties in designtime
    Private Sub Text1_Change()
        Dim x&
        x = Text1.SelStart
        If Left(Text1, 8) Like "########" Then
            Text1 = Left(Text1, 8)
            Text1.Tag = Text1
        Else
            Text1 = Text1.Tag
        End If
        Text1.SelStart = x
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guest
    sorry about that. i was not able to test the code.
    here's the tested code.

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (Len(Text1) > 7 Or Not IsNumeric(Chr(KeyAscii))) And _
    KeyAscii <> vbKeyReturn And _
    KeyAscii <> vbKeyBack Then
    KeyAscii = 0
    End If
    End Sub

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