I'm trying to take input keypress event and move the text it would have typed into a textbox to a different textbox instead.

textBox1 has a length limit of 1 so I dont actually have to prevent text going into the box because the textbox is already full

I just need to put the character that would have been typed into the next textbox

Lines 16 and 24 are the problem afaik

            '*******************************************************
            'Handle all typeable characters in populated(full) boxes
            '*******************************************************

            If (e.KeyCode > 31 And e.KeyCode < 127) Then

                'Only handle full textboxes (empty are already handled)
                If Not txtBox.Text = "" Then

                    For Each o As Object In Me.Controls 'determine which textbox is to the left
                        If TypeOf o Is TextBox Then
                            If Val(txtBox.Name.Substring(11, 2)) > 8 Then 'if it's bigger than 8 then +1 will be a 2 digit number (10+)
                                If o.name.contains("inputTxtBox" + Val(txtBox.Name.Substring(11, 2) + 1).ToString) Then 'Select the txtBox to the right
                                    If o.text = "" Then 'only if the txtbox to the right is empty
                                        o.focus() 'focus it
                                        o.text = e.KeyValue.ToString '//THE PROBLEM
                                    End If
                                End If

                            ElseIf Val(txtBox.Name.Substring(11, 2)) <= 8 Then 'if it is 8 or less we need to add the 0 to the string because +1 will be 9 or less
                                If o.name.contains("inputTxtBox0" + Val(txtBox.Name.Substring(11, 2) + 1).ToString) Then 'Select the txtBox to the right
                                    If o.text = "" And o.enabled = True Then 'only if the txtbox to the right is empty and enabled
                                        o.focus() 'focus it
                                        o.text = e.KeyValue.ToString '//THE PROBLEM
                                    End If
                                End If
                            End If
                        End If
                    Next

with e.keydata letters work (sort of) but numbers are things like d1 d2 etc
I just need to address the real character. The rest of the code works fine it's just I dont know how to tell it to put in the number "1" instead of "d1" etc

Edited 3 Years Ago by robert.knighton.79: clarification

Thanks, I'm certain that will work, and once I figure out why my program is having a meltdown I will test it...

Marking it solved because that should work

I take it back... it's almost solved..

Chr(e.KeyCode) always returns capital letters

so whether c is typed or SHIFT+c

I get C either way

Edited 3 Years Ago by robert.knighton.79: because im an idiot?

Also cant get !@#$%^& asterik ()
because it only outputs
1234567890

anything requiring the shift key cant be printed this way

Chr(e.KeyCode) always returns capital letters

Yes, because the KeyCode property doesn't include shift state. There's also a Shift property for KeyEventArgs that tells you whether the shift key was pressed (and Alt, and Ctrl). You might consider whether the KeyData or KeyValue properties suit your needs better.

I have tried with all 3 (KeyData, KeyValue, and KeyCode). They all do exactly the same thing when passed to chr().

KeyValue is the only one returning actual ASCII codes. Keycode returns codes that correspond to keyboard layout and keydata returns letters just like chr(KeyValue) would but breaks numbers and special characters into codes.

How would I detect the use of Shift key? If that information actually gets attached at the same time of the keydown I could use an If statement to modify the returning ascii values appropriately.

EDIT
Code I have so far is mostly the same as above but shows use of chr()

            '*******************************************************
            'Handle all typeable characters in populated(full) boxes
            '*******************************************************

            If (e.KeyCode > 31 And e.KeyCode < 127) Then

                'Only handle full textboxes (empty are already handled)
                If Not txtBox.Text = "" Then

                    For Each o As Object In Me.Controls 'determine which textbox is to the left
                        If TypeOf o Is TextBox Then
                            If Val(txtBox.Name.Substring(11, 2)) > 8 Then 'if it's bigger than 8 then +1 will be a 2 digit number (10+)
                                If o.name.contains("inputTxtBox" + Val(txtBox.Name.Substring(11, 2) + 1).ToString) Then 'Select the txtBox to the right
                                    If o.text = "" Then 'only if the txtbox to the right is empty
                                        o.focus() 'focus it
                                        o.text = Chr(e.KeyValue) 'Cant modify for use of shift key??
                                    End If
                                End If

                            ElseIf Val(txtBox.Name.Substring(11, 2)) <= 8 Then 'if it is 8 or less we need to add the 0 to the string because +1 will be 9 or less
                                If o.name.contains("inputTxtBox0" + Val(txtBox.Name.Substring(11, 2) + 1).ToString) Then 'Select the txtBox to the right
                                    If o.text = "" And o.enabled = True Then 'only if the txtbox to the right is empty and enabled
                                        o.focus() 'focus it
                                        o.text = Chr(e.KeyValue) 'Cant modify for use of shift key??
                                    End If
                                End If
                            End If
                        End If
                    Next



                End If




            End If

Edited 3 Years Ago by robert.knighton.79: added code

How would I detect the use of Shift key?

Please read my post again. Not only did I describe exactly what you're asking, I linked to documentation on the KeyEventArgs class so that you can get full details.

you're right, I missed the link somehow. My appologies. Thank you.

The following works for letters but if I want to handle numbers/symbols I guess I'll have to create a large select case statement for them since they dont translate as evenly as letters do.

If e.Modifiers = Keys.Shift Then
    o.focus() 'focus it
    o.text = Chr(e.KeyValue)
Else
    o.focus() 'focus it
    o.text = Chr(e.KeyValue + 32)
End If

thanks again to those who helped!

This question has already been answered. Start a new discussion instead.