|
-
Aug 25th, 2003, 03:41 PM
#1
Thread Starter
Addicted Member
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...
-
Aug 25th, 2003, 03:45 PM
#2
Check for it on KeyPress event or validate the whole thing on the Leav or Validate events.
-
Aug 25th, 2003, 03:46 PM
#3
Hyperactive Member
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:
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
-
Aug 25th, 2003, 04:06 PM
#4
Thread Starter
Addicted Member
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...
-
Aug 25th, 2003, 04:15 PM
#5
Hyperactive Member
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("|","")
-
Aug 25th, 2003, 04:39 PM
#6
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.
-
Aug 25th, 2003, 05:05 PM
#7
Thread Starter
Addicted Member
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...
-
Aug 25th, 2003, 05:29 PM
#8
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
~
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]
-
Aug 25th, 2003, 06:10 PM
#9
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|