|
借用论坛上的一个汉字简拼输入的例子,但是没有效果,调试时发觉
在执行完.value=null(==>所指)后,不执行sendkeys
却跳到了Err==>所指)
Public Function ComboBoxKeyPress(KeyAscii As Integer) As String
'调用方法 在组合框的keypress方法中加入:
'--------------------------------------------
' If ComboBoxKeyPress(KeyAscii) <> "" Then KeyAscii = 0
'--------------------------------------------
On Error GoTo Err
Dim i As Integer
With Screen.ActiveControl
If .ControlType = acComboBox And (KeyAscii >= Asc("a") And KeyAscii <= Asc("z")) Then
'只能由组合框输入小写字母时调用
ComboBoxKeyPress = Nz(HZPY(Left(.Text, .SelStart))) & Chr(KeyAscii)
While HZPY(Left(.ItemData(i), .SelStart + 1)) <> ComboBoxKeyPress And i < .ListCount - 1
i = i + 1
Wend
If i <> .ListCount And Mid(.ItemData(i), .SelStart + 1, 1) <> Chr(KeyAscii) Then
ComboBoxKeyPress = Left(.ItemData(i), .SelStart + 1)
==> .Value = Null
SendKeys ComboBoxKeyPress
Else
ComboBoxKeyPress = "" '为英文时不代换,否则会进入死循环
End If
End If
End With
Exit Function
Err:
==> ComboBoxKeyPress = ""
End Function
|
|