设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 22737|回复: 111
打印 上一主题 下一主题

[模块/函数] 支持拼音首字母的组合框函数及实例

[复制链接]
跳转到指定楼层
#
发表于 2005-1-19 21:31:00 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
ublic 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

下面是一个范例:

游客,如果您要查看本帖隐藏内容请回复

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享分享 分享淘帖 订阅订阅
111#
发表于 2018-8-29 12:30:05 | 只看该作者
学习一下
回复

使用道具 举报

110#
发表于 2017-11-6 13:27:23 | 只看该作者
下来看一下,正在找呢
109#
发表于 2017-6-11 16:25:30 | 只看该作者
感谢。经典之作。
108#
发表于 2017-4-27 14:08:18 | 只看该作者
学习学习
回复

使用道具 举报

107#
发表于 2017-4-9 20:49:19 | 只看该作者
学习学习   正好要用
106#
发表于 2016-7-6 14:00:39 | 只看该作者
111111111111
105#
发表于 2014-12-1 08:58:00 | 只看该作者
看看











回复

使用道具 举报

104#
发表于 2014-11-7 19:49:53 | 只看该作者
这下谢谢
回复

使用道具 举报

103#
发表于 2014-7-19 22:41:23 | 只看该作者
学习分享一样快乐
102#
发表于 2014-6-18 17:18:17 | 只看该作者
学习学习!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-22 01:55 , Processed in 0.113329 second(s), 37 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表