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.

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
    DoEvents

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

    ' Release Alt.
    keybd_event VK_ALT, 0, KEYEVENTF_KEYUP, 0
    DoEvents
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.

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.

How about using the Shift parameter of the KeyDown Event?

Shift - Indicates the state of the SHIFT, CTRL, and ALT keys.

http://msdn.microsoft.com/en-us/library/aa733630%28v=VS.60%29.aspx

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.