Solved👍 Removeing Certain Characters From a Textbox

Posts 1–9 of 9 · Page 1 of 1
👍 Removeing Certain Characters From a Textbox
I'm trying to limit what the user can enter into a textbox. The easy part is knowing if they tried to type that character, the hard part is removing that single character. Does anyone know how? e.SuppressKeyPress is really buggy and not working right.

I've tried Textbox1.text.replace("|", "") and Textbox1.text.remove(Textbox1.textlength - 1), no luck there.
Silly question (..but without seeing the code), did you just call

Textbox1.text.replace("|", "")

or

TextBox1.Text = Textbox1.text.replace("|", "")

? Because strings are immutable, the first one won't work as you might expect.
Quote Originally Posted by abuckau907 View Post
Silly question (..but without seeing the code), did you just call

Textbox1.text.replace("|", "")

or

TextBox1.Text = Textbox1.text.replace("|", "")

? Because strings are immutable, the first one won't work as you might expect.
Both of them still won't work.

Also, I'm using GetAsyncKeyState to see if the user presses the button.


---------- Post added at 11:26 AM ---------- Previous post was at 11:24 AM ----------

Quote Originally Posted by DawgiiStylz View Post
Simple really
Code:
 Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyz1234567890" & Chr(8) ' backspace
        If allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
It says the e.KeyChar is not a member, even though I have 'ByVal e As System.Windows.Forms.KeyEventArgs' included.
Simple really
Code:
 Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyz1234567890" & Chr(8) ' backspace
        If allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
As you say, if you can capture (event) when user inputs, you can do a nooby remove

tb=textbox

tb.text.Remove(tb.text.length -1, 1)
tb.SelectionStart = tb.text.length


Or something along those lines.

What I do is:
I remove the LAST input char, and move the selection point to the end. (So the user won't start typing from the start )
Quote Originally Posted by Jorndel View Post
As you say, if you can capture (event) when user inputs, you can do a nooby remove

tb=textbox

tb.text.Remove(tb.text.length -1, 1)
tb.SelectionStart = tb.text.length


Or something along those lines.

What I do is:
I remove the LAST input char, and move the selection point to the end. (So the user won't start typing from the start )
That didn't remove the text though
Quote Originally Posted by Cryptonic View Post


That didn't remove the text though
Silly me

Forgot too do:

tb.Text = tb.Text.Remove(***)
'Else it's not assigning the new value as the content in the tb
"Also, I'm using GetAsyncKeyState to see if the user presses the button."

I assumed you were using one of the textbox_keypress_events..kind of an important detail : p
Quote Originally Posted by abuckau907 View Post
"Also, I'm using GetAsyncKeyState to see if the user presses the button."

I assumed you were using one of the textbox_keypress_events..kind of an important detail : p
Yes, it's fixed now. I was using the 'ByVal e As System.Windows.Forms.KeyEventArgs' and for some reason, was conflicting with the replace code...

Thanks for all your help

/solved
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us