thefordness
New Member
- Joined
- Oct 23, 2013
- Messages
- 7
I have a routine here that uses KeyDown to get the value of a key press in a userform and use it for a wildcard search in a list box. I refining the code and making changes to accommodate my list and I have discovered that the KeyDown integer values don't always correspond to the ascii table. Chr(Input1) is using the ascii value of the variable to create your search filter as you type. For example: using this code, I get the integer 189 when I press the - key (Hyphen) instead to the ascii value of 45, and the Chr of 189 is the ½ (Fraction one half) which useless for a wildcard search. This works fine for standard alpha characters though. The routine needs to run every time a key is pressed, so I'm not sure if there's a better way to do this other than KeyDown, or if there is a way to get the desired output from KeyDown.
Other example keys that also don't return ascii values: ! " # $ % & ' ( ) * + , - . / etc
To give credit, this was derived from some code found at Ozgrid.com thread #65707
Public Input2 As String
Private Sub ListBox1_KeyDown(ByVal Input1 As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case True
Case Input1 = vbKeyBack
ResetBttn_Click
Case Input1 = vbKeyEscape
Unload Me
Case Input1 = vbKeyReturn
OKBttn_Click
Case (Input1 >= 32 And Input1 <= 126) 'ASCII printable characters (character code 32-127)
Input2 = Input2 & Chr(Input1)
TextBox1.Value = Input2 'this displays the text s you type
FillListBoxByWildChars Input2, [LBTitle], Me.ListBox1
Case Else
End Select
End Sub
Other example keys that also don't return ascii values: ! " # $ % & ' ( ) * + , - . / etc
To give credit, this was derived from some code found at Ozgrid.com thread #65707
Public Input2 As String
Private Sub ListBox1_KeyDown(ByVal Input1 As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case True
Case Input1 = vbKeyBack
ResetBttn_Click
Case Input1 = vbKeyEscape
Unload Me
Case Input1 = vbKeyReturn
OKBttn_Click
Case (Input1 >= 32 And Input1 <= 126) 'ASCII printable characters (character code 32-127)
Input2 = Input2 & Chr(Input1)
TextBox1.Value = Input2 'this displays the text s you type
FillListBoxByWildChars Input2, [LBTitle], Me.ListBox1
Case Else
End Select
End Sub