Results 1 to 12 of 12

Thread: text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Smile text box

    i was wnodering how can you make a message box appear when
    the person types letters instead of charictors in the text box ?!!!!!!!

    an other question is that how can you make a massage box appear if there wasn't any @ in the textbox?!!?
    thank you in advance

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: text box

    youll be able to find answers to your questions by first searching the forum because a lot of the time, your question has been answered. for example, the @ sign question:
    http://www.vbforums.com/showthread.p...validate+email

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Re: text box

    but what about the integer thing i couldn't find it?!!!

  4. #4
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: text box

    there are lo of ways. Look in the ASC CODE CHART inside VB help to see the character's number.

    And just put in the keypress event:

    Select Case KeyAscii
    Case 1 to 10, 15 to 20
    KeyAscii = 0
    MsgBox "TYPE ANOTHER CHAR!"
    Exit Sub
    End select

    Of course instead of (1 to 10, 15 to 20) use all the chars you would like to filter.

    About the other just use:
    If InStr(1,Text1,"@") = 0 then msgbox "Please enter an @ in your textbox"

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: text box

    The only problem with creating a per key filter algorithm for a textbox is that it can't handle a copy and paste operation by the user (say data copied from notepad then pasted into the textbox). To compensate, patching additional code in the change event to recheck the string can get messy since you'll have to worry about the cursor position after correcting the input.

    The best approach IMO, is to use the validate event. Check the input only after the user has finished entering the data for the textbox and has attempted to moved to another control. All other controls will have to have their CausesValidation property set to True.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Re: text box

    i didn't get the folter thing to be honest

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Re: text box

    filter * thing i meant

  8. #8
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: text box

    filter would be to "forbid" the user to use those chars.
    for example, if you would like him not to use character's 20 to 30 and 40 to 45 then use

    Select Case KeyAscii
    Case 20 to 30, 40 to 45
    KeyAscii = 0
    MsgBox "TYPE ANOTHER CHAR!"
    Exit Sub
    End select

    Of course i have no idea which cahrs those are... just was an example

    EDIT:
    And leinad31 is right, but if you know how will use the program and he's not stupid then you dont need to do anything... if the user could be a dumb person then you need to do something... I dont know what!

  9. #9
    Member
    Join Date
    May 2006
    Location
    India
    Posts
    45

    Re: text box

    I did not want to start a new thread so I thought I will post it here..
    I would like to know the code required to be put in the keypress event of the textbox so that the user is allowed to enter only 0-9 and one decimal point..

    And also disable copy and paste of data into the textbox..

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Re: text box

    would you explain it more
    thank you

  11. #11
    Member
    Join Date
    May 2006
    Location
    India
    Posts
    45

    Re: text box

    Well i need a text box that accepts only number(0-9) and one decimal point..
    it should not let the user enter alphabets..
    this text box is to enter angles..
    So it'l b of the format:
    Eg: 56.678956 or 109.344532
    So I want to implement validations for being able to only enter numbers and just 1 decimal point.
    I hope that makes it clear

  12. #12
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: text box

    To allow only numric characters in Text box:
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     Select Case KeyAscii
    3.         Case Is < 32               ' Control keys are OK.
    4.         Case 48 To 57              ' This is a digit.
    5.         Case Else                  ' Reject any other key.
    6.             KeyAscii = 0
    7.     End Select
    8. End Sub
    CS

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