Return Key

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I am new to VB.Net and I am developing a stand-alone app
that will only be using a RF scanner to enter
information. I was curious if anyone knew of any articles
or source code on how I could get the text box to execute
to TAB/ENTER when a certain number of characters have been
reached within a text box.
 
Chris,
maybe this code will help you. Place 2 textboxes on the form and write this
code

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Len(TextBox1.Text) >= 5 Then
e.Handled = True
Call Done()
End If
End Sub

Private Sub Done()
TextBox2.Select()
TextBox2.Text = "No more characters. Do something else"
End Sub

You can call any sub or function instead of my DONE sub
Vlad
 
Chris said:
I am new to VB.Net and I am developing a stand-alone app
that will only be using a RF scanner to enter
information. I was curious if anyone knew of any articles
or source code on how I could get the text box to execute
to TAB/ENTER when a certain number of characters have been
reached within a text box.

By doing a "Tab", i'm guessing you mean shifting the focus
to the next textbox. That would be done like this:

Private Sub txtOne_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles txtOne.TextChanged

'where txtOne and txtTwo are two textboxes on the form
If txtOne.Text.Length = 5 Then
txtTwo.Focus()
End If
End Sub

By doing and enter, I presume you want some action(s) to occur
when the box is full. For this, put the action into a sub(eg. MySub)
and call the sub like this:

Private Sub txtTwo_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles txtTwo.TextChanged

If txtOne.Text.Length = 5 Then
Call MySub()
End If
End Sub

Hope this helps,
 
Back
Top