hi there i just have a problem with my program i used the keycodes of vb wherein every time i enter a letter from A-Z it will display each letter together with a special character " | ". Im done with this but my problem is, the letters were displaying from right to left. please help me with this.

here is my code:

If KeyAscii = 13 Or KeyAscii = 9 Then
fname_txt.SetFocus
surname_txt.Text = StrConv(surname_txt.Text, 1)
End If

If KeyAscii <= 90 Or KeyAscii >= 65 Then
surname_txt.Text = Format(" " & "|" & " " & surname_txt.Text & " ")
End If

Thanks in advance!

Try this:

If KeyAscii = 13 Or KeyAscii = 9 Then
    surname_txt.Text = StrConv(surname_txt.Text, 1) + " | "
    fname_txt.SetFocus
    Exit Sub
End If

If KeyAscii <= 90 Or KeyAscii >= 65 Then
    surname_txt.Text = surname_txt.Text + " | "
    surname_txt.SelStart = Len(surname_txt.Text)
End If

Basically, every time you add a character, you need to reposition the cursor at the end of the text. I'm assuming you want a vertical bar at the beginning as well as at the end?

One other little thing...the TAB keystroke doesn't trigger the KeyPress event, so testing for it's keycode doesn't really do anything.

Hope this helps! Good luck!

super thanks BitBit.. it works well ! ^^

but I have another problem the backspace doesnt work well.. every time i press it a vertical bar appears which should not..it should just delete the previous letter that was typed.. can you help me with that,too?

Thanks for your reply! ^^

Just test for the keycode for backspace (you'll have to look it up) and trim off the requisite number of characters, then do an Exit Sub.

Be sure to mark this thread "solved", too. Thanks, and Happy Coding!

Nothing to add, I saw the post on a 2 year old thread, bitblit gave you the solution. :)

okidoks! super thanks po! godbless! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.