Further to Solution 1 (recommended), assuming you stick with your current approach then
TextBox1.Text
is the contents of the text box.
However, I think you should use
Validating
event in preference to the
OnKeyPress
event.
You can still use
OnKeyPress
to ensure that only 0-9, comma and backspace are accepted e.g.
If (Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not (New Integer() {8, Asc("-"), Asc(",")}.Contains(Asc(e.KeyChar))) Then
e.Handled = True
Your attempt was close but you need to set
e.Handled = True
to ignore the key