Adding a input mask

  • Thread starter Thread starter Crirus
  • Start date Start date
In the KeyPress EventDim ch As String

ch = Chr$(KeyAscii)
If Not (ch >= "0" And ch <= "9") Then
' Cancel
KeyAscii = 0
End said:
I need to allow only numbers into a text box

Regards - OHM# (e-mail address removed)
 
One Handed Man said:
In the KeyPress EventDim ch As String

ch = Chr$(KeyAscii)
If Not (ch >= "0" And ch <= "9") Then
' Cancel
KeyAscii = 0


Regards - OHM# (e-mail address removed)

How to suppress inserting chars from the clipboard? ;-)
 
Hey, I cant write everything from scratch each time, I am after all One
Handed Man.

;-)

Regards - OHM#


Armin said:
How to suppress inserting chars from the clipboard? ;-)

Regards - OHM# (e-mail address removed)
 
One Handed Man said:
Hey, I cant write everything from scratch each time, I am after all
One Handed Man.

;-)

Yes, I also wondered where it has been asked and answered the last time. :)
 
I sow some sample of input mask so the text box dont consider any character
that dont fit the mask..but lost it
 
Hi Armin,
How to suppress inserting chars from the clipboard? ;-) (saw it, but also
know it)

That you can do with a isnumeric and a leave.

I hope this helps you?

:-)))))

Cor
 
Crirus said:
Any straight answer?
I need another inputs restrictions too, not only numeric

I would not restrict the input. I'd check the correct format in the validate
event (or wherever you need the value latest), usually by trying to convert
it to the destination data type (e.g. Decimal.Parse) and catching thrown
exceptions, or by calling a function like Double.TryParse.
 
Hi Crirus,

As addition from the sample of OHM this sample.
And watch that you add with the sample of OHM the allowance of the backspace
08 keyvalue other wise the user cannot make corrections)

You can in both samples of course use any character you want to exclude.
Although this is a value sample.

Cor
\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.textbox1.MaxLength = 2
End Sub
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(textbox1.Text) OrElse CInt(textbox1.Text) = 0 _
OrElse CInt(textbox1.Text) > 10 Then
MessageBox.Show("Only 1 to 10 is allowed")
textbox1.Focus()
End If
End If
End Sub
///
 
I think its time we got paid for this Cor, he's probably earning $150 per
hour and they think he's writing it all himself !!!

;-)

Regards - OHM#
Hi Crirus,

As addition from the sample of OHM this sample.
And watch that you add with the sample of OHM the allowance of the
backspace 08 keyvalue other wise the user cannot make corrections)

You can in both samples of course use any character you want to
exclude. Although this is a value sample.

Cor
\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.textbox1.MaxLength = 2
End Sub
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(textbox1.Text) OrElse CInt(textbox1.Text)
= 0 _ OrElse CInt(textbox1.Text) > 10 Then
MessageBox.Show("Only 1 to 10 is allowed")
textbox1.Focus()
End If
End If
End Sub
///

Regards - OHM# (e-mail address removed)
 
LOL

First, I earn 5$ per hour. (EEST, you know)
Second this is my particular project for a Internet Tick Based game that you
probably whould like to play it for free sometime in the future :)
 
And I know how to restrict with code the input, but I cant remember one
sample tat use a string as a mask and I'm crazy about using that way
 
Hi Crirus,

I think you can do that with the sample I did send you.

When I say textbox > 10 you also can check it against any regular
expression in my opinion.

But as far as I know there is no standard property that does that for you
(and when you make a custom textbox you do the same again).

Cor
 
Right now I found MaskedEdit control ocx on google... there is one in NET?

If you download the VB.Net Resource kit, it includes ComponentOne suite of
controls and the textbox in that has a good masked edit property.
 
Back
Top