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?
Printable View
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?
Check for it on KeyPress event or validate the whole thing on the Leav or Validate events.
Block it outQuote:
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?
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Chr(Asc("|")) Then e.Handled = True End If End Sub
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"Quote:
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.
If sText.IndexOf("|") > -1 Then
MsgBox("Quit Using |'s")
End if
heh :D
You can even go as far as removing then if you want
sText = sText.Replace("|","")
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.
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.
although Asc and Chr are very good, they seem to be very vb6 based, this would work also without any conversions...
VB Code:
If e.KeyChar = "|" Then e.Handled = True End If
Quote:
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:
If e.KeyChar = "|" Then e.Handled = True 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 :D