| 网站首页 | 新闻 | 新书 | 专家 | 技巧 | 源码作品 | 工具/资源 | 商城 | 风采 | 留言 | 论坛 | 网址 | 承接 | 
您现在的位置: Access/Office中国 >> 技巧 >> Access >> 窗体标准控件 >> 文章正文 用户登录 新用户注册
[图文]支持拼音首字母的组合框函数及实例         ★★★
支持拼音首字母的组合框函数及实例
作者:trynew『… 文章来源:Access中国/Office中国 点击数: 本日:{$DayHits} 更新时间:2005-8-5 2:28:53
发贴心情 支持拼音首字母的组合框函数及实例

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

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    专 题 栏 目
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    我的风格窗
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)