Results 1 to 9 of 9

Thread: Delimiter in a text box (RESOLVED)

  1. #1

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142

    Delimiter in a text box (RESOLVED)

    I use this: "|" as the delimiter in my text file, so I dont want the user to put that character into a textbox, or if they do I wnat to show a message box to tell them they cant use it. How can I do that?
    Last edited by The Phoenix; Aug 25th, 2003 at 05:06 PM.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Check for it on KeyPress event or validate the whole thing on the Leav or Validate events.

  3. #3
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Re: Delimiter in a text box

    Originally posted by The Phoenix
    I use this: "|" as the delimiter in my text file, so I dont want the user to put that character into a textbox, or if they do I wnat to show a message box to tell them they cant use it. How can I do that?
    Block it out

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.  
    3.         If e.KeyChar = Chr(Asc("|")) Then
    4.             e.Handled = True
    5.         End If
    6.  
    7.     End Sub

  4. #4

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Thanks! Geez, I guess I need to take a break. I'm missing obvious answers here. I should have known about the "keyPress" event. I'm not THAT much of a beginner.

    I know that you can use the indexOf funstion to search for the instance of a character in a string, right? How would I use that to solve this problem?

    This whole question stems from a project I did last semester, and a buddy of mine had this feature on his program. He said he used the "indexOf" feature to do it, but I didnt get t see his code.

    I am now writing a small program for a friend and needed to do this, but couldn't figure out the indexOf thing, and I became obsessed with figuring it out, and didnt even think of using keyPress.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  5. #5
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Originally posted by The Phoenix
    Thanks! Geez, I guess I need to take a break. I'm missing obvious answers here. I should have known about the "keyPress" event. I'm not THAT much of a beginner.

    I know that you can use the indexOf funstion to search for the instance of a character in a string, right? How would I use that to solve this problem?

    This whole question stems from a project I did last semester, and a buddy of mine had this feature on his program. He said he used the "indexOf" feature to do it, but I didnt get t see his code.

    I am now writing a small program for a friend and needed to do this, but couldn't figure out the indexOf thing, and I became obsessed with figuring it out, and didnt even think of using keyPress.
    Dim sText as String = "This is | as Test"
    If sText.IndexOf("|") > -1 Then
    MsgBox("Quit Using |'s")
    End if

    heh

    You can even go as far as removing then if you want
    sText = sText.Replace("|","")

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Although Hinder's first code he gave is better because it wont even let them type | into the box. So there will be no need to check for it.

  7. #7

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Thanks Hinder!

    Yeah I thought about using his first code, but I dont like limiting the keys they can type, cause then some idiot would set there and press the same key a thousand times....

    Of course, I could pop up a message box telling them shy they cant press that key...

    Oh well, Thanks again guys! I'll use one ore the other.

    BTW, I cant believe how patient you guys are. You've prbably heard these same dumb easy questions from a thousand other people, yet you still answer them. For all newbies everywhere, I thank you.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  8. #8
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    although Asc and Chr are very good, they seem to be very vb6 based, this would work also without any conversions...
    VB Code:
    1. If e.KeyChar = "|" Then
    2.             e.Handled = True
    3.         End If
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  9. #9
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Originally posted by dynamic_sysop
    although Asc and Chr are very good, they seem to be very vb6 based, this would work also without any conversions...
    VB Code:
    1. If e.KeyChar = "|" Then
    2.             e.Handled = True
    3.         End If

    So tough to break the old habbits... I didn't realize it would take a straight character, I guess I have some of my own code to tweak

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