reading single character from textbox

Blitzkrieg99
02-05-2004, 12:55 AM
Hello everyone.

Suppose I have a textbox and the user inputs some characters. Is there a way I can read off a particular character and display it on a messagebox? ie The user types "abcdef" and I write a code that will just display, say, the third character (in this case 'c') typed by the user.

Also, is it possible for me to link 2 textboxes such that after typing a specified number of characters in one textbox, the cursor 'jumps' to the next textbox. It works basically like those CD-Key thingies. Like how after you type the first four characters, the control jumps to the next textbox.

Thanking you for your time.

Blitzkrieg99
02-05-2004, 02:24 AM
I managed to overcome the first problem using Microsoft.VisualBasic.Mid() function. I am stuck with the second one, whereby I need to jump from TextBox1 to TextBox2 after, say, 2 characters have been typed in TextBox1. Thanks

Syko10-96
02-05-2004, 04:43 AM
Hello,

You could try something like this in the KeyPress event for your first text box:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Len(Text1.Text) > 1 Then
KeyAscii = 0 ' sets last key pressed to Null so it doesn't appear in the textbox
Text2.SetFocus
End If
End Sub


Hope this helps :)

Blitzkrieg99
02-05-2004, 06:46 PM
Thanks for that Syko10-96. It seems that SetFocus in .NET has been changed to Focus. No matter what I tried, the jumping effect just didnt take place. This is even when I replaced the TextBox2.Focus line with ActiveControl = TextBox2. The only thing I was left to do was to restrict the max. no. of characters for TBox1 and have the TabStop indexes for TBoxes 1 and 2 run consecutively. Regards.

Csharp
02-06-2004, 01:18 AM
easiest way would be something like this ...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.MaxLength = 2
TextBox2.MaxLength = 2
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.TextLength = 1 Then
TextBox2.Focus()
End If
End Sub

Blitzkrieg99
02-06-2004, 01:49 AM
Works just the way I need it to. Thanks alot for that C Sharp.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum