Results 1 to 7 of 7

Thread: [RESOLVED] Varify Input

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Varify Input

    I have code to check the input for specific characters in a text box.
    My code catches the incorrect characters, gives a warning, but after the user closes the msgbox, the incorrect character is still entered

    I am sure this will be a simple solution but I can't figure it out at the moment.

    I have tried the following code in the KeyDown, KeyPress and the KeyUp and I get the same problem each time.
    vb Code:
    1. Dim tmpDate As String
    2.     tmpDate = txtMembership(Index).Text
    3.    
    4.     Select Case Index
    5.         Case 11, 12, 13, 15
    6.             Select Case KeyAscii
    7.                 Case 8          'backspace
    8.                 Case 47         '/forward slash
    9.                 Case 48 To 59   'numbers
    10.                 Case 127        'Delete key
    11.                 Case Else
    12.                     MsgBox "You can only enter numbers and the ' / ' seperator when entering dates.", _
    13.                             vbOKOnly + vbInformation, "Date Format"
    14.                     'remove last character entered
    15.                     'Exit Sub
    16.                     txtMembership(Index).Text = tmpDate
    17.             End Select
    18.     End Select
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Varify Input

    just spit balling...I usually test before posting but something like:

    txtMembership(Index).Text = mid(tmpDate,1,len(tmpDate) - 1)

  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Varify Input

    Thanks Tyson, but that doesn't work - same problem
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4

  5. #5

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Varify Input

    Quote Originally Posted by MartinLiss
    Pseudocode:

    Code:
    If KeyAscii isn't valid Then
        error message
        KeyAscii = 0
    End If
    Thanks Martin, I knew I had done this before, but just couldn't remember the solution

    Does it make any difference as to which event I put this in:
    KeyDown, KeyUp or KeyPress?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  6. #6

  7. #7

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Varify Input

    Quote Originally Posted by MartinLiss
    Of those, KeyPress is the only one that gives you the keyascii value so the choice is clear.
    Should have checked that. I had it in that one, so I hadn't looked again at the other two, both KeyCode.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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