设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

支持拼音首字母的组合框函数及实例

1970-1-1 08:00| 发布者: trynew『文章』| 查看: 3757| 评论: 0

发贴心情 支持拼音首字母的组合框函数及实例

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

Function HZPY(hzstr As String) As String
Dim p0 As String, C As String, str As String
Dim i As Integer, j As Integer
p0 = "吖八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗"
For i = 1 To Len(hzstr)
    C = "z"
    str = Mid(hzstr, i, 1)
    If Asc(str) > 0 Then
        C = str
    Else
        For j = 1 To 26
            If Mid(p0, j, 1) > str Then
                C = Chr(95 + j)
                Exit For
            End If
        Next
    End If
    HZPY = HZPY + C
Next
End Function

原文:http://www.office-cn.net/BBS/dispbbs.asp?BoardID=2&ID=24443

最新评论

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 17:46 , Processed in 0.078465 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部