Input box

  • Thread starter Thread starter W. Adam
  • Start date Start date
W

W. Adam

I have a form which displays info. On top of it there is a text box for
input box which lets you put number from 1 thu 10.
My question is "What do i need to do in order not to let the user go past
it(the input box) if he/she did not enter the correct value.
Thanks in advance
..
 
* "W. Adam said:
I have a form which displays info. On top of it there is a text box for
input box which lets you put number from 1 thu 10.
My question is "What do i need to do in order not to let the user go past
it(the input box) if he/she did not enter the correct value.
Thanks in advance

Don't restrict the user from pasting/entering whatever he wants.
Instead, add validation code to the control's 'Validating' event handler
and use an ErrorProvider to make the user aware of malformed input.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
Hi W,

I made an example for you, this is a situation where the OrElse works fine.

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
Private Sub textbox1_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles textbox1.LostFocus
textbox1.Focus()
End Sub
I hope this helps a little bit?

Cor
 
Back
Top