Was having trouble printing special characters using Ascii codes for this two characters:

**Ñ and ñ. **

I'm trying to enable inserting them on textboxes using Keypress event but to no avail. But since the Alt key doesn't have Ascii equivalent, I can't figure it out. I would want to try Keyup or Keydown but want to have some idea first.

Printing the 2 characters above using Alt key plus their numeric (from numeric keypad)

Anyways, does the FN key in laptops have ascii? So that inserting those 2 symbols would work both on PC and laptop.

4 Years
Discussion Span
Last Post by TnTinMN

I would use an if statement to check if ñ has to be entered if just n was pressed...

If KeyCode = vbKeyN Or KeyCode = vbKeyn Then
     ''code to convert to ñ ...
  End If

Code to convert to symbol, I would imitate the alt key press event with its number (ALT & 0241) in this case. Then set that to a value string and print it in text box...

Have a look here for all the special keyboard numbers, letters and accents - special characters

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As _
    Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal _
    dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_ALT = &H12
Private Const VK_TAB = &H9

' Grab all of the text in the WebBrowser control.
Private Sub Command1_Click()
    ' Press Alt.
    keybd_event VK_ALT, 0, 0, 0

    ''Add code here for the numbers, say 0241 for ñ

    ' Release Alt.
    keybd_event VK_ALT, 0, KEYEVENTF_KEYUP, 0
End Sub

Another way would be to just convert the letters with something like this -

Public Function ReplaceCharacters(ByVal strDataToCheck As String) As String

    strDataToCheck = Replace(strDataToCheck, Chr(153), Chr(214)) 'Ö
    strDataToCheck = Replace(strDataToCheck, Chr(154), Chr(220)) 'Ü
    strDataToCheck = Replace(strDataToCheck, Chr(142), Chr(196)) 'Ä

    strDataToCheck = Replace(strDataToCheck, Chr(148), Chr(246)) 'ö
    strDataToCheck = Replace(strDataToCheck, Chr(129), Chr(252)) 'ü
    strDataToCheck = Replace(strDataToCheck, Chr(132), Chr(228)) 'ä

    strDataToCheck = Replace(strDataToCheck, Chr(225), Chr(223)) 'ß

    m_txtCompleteLine = strDataToCheck

End Function

Text1.Text = Text1.Text & m_txtCompleteLine

To setup for both pc and lappie, have a look this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.