vb6.0怎样实现汉字的拼音如text1输入“拼音”就msgbox(pinyin)
发布网友
发布时间:2022-04-26 15:56
我来回答
共4个回答
热心网友
时间:2023-10-13 02:56
Private Function py(mystr As String) As String '获得汉字的拼音简码
On Error Resume Next
If Asc(mystr) < 0 Then
If Asc(Left(mystr, 1)) < Asc("啊") Then
py = "0"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("啊") And Asc(Left(mystr, 1)) < Asc("芭") Then
py = "A"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("芭") And Asc(Left(mystr, 1)) < Asc("擦") Then
py = "B"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("擦") And Asc(Left(mystr, 1)) < Asc("搭") Then
py = "C"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("搭") And Asc(Left(mystr, 1)) < Asc("蛾") Then
py = "D"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("蛾") And Asc(Left(mystr, 1)) < Asc("发") Then
py = "E"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("发") And Asc(Left(mystr, 1)) < Asc("噶") Then
py = "F"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("噶") And Asc(Left(mystr, 1)) < Asc("哈") Then
py = "G"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("哈") And Asc(Left(mystr, 1)) < Asc("击") Then
py = "H"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("击") And Asc(Left(mystr, 1)) < Asc("喀") Then
py = "J"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("喀") And Asc(Left(mystr, 1)) < Asc("垃") Then
py = "K"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("垃") And Asc(Left(mystr, 1)) < Asc("妈") Then
py = "L"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("妈") And Asc(Left(mystr, 1)) < Asc("拿") Then
py = "M"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("拿") And Asc(Left(mystr, 1)) < Asc("哦") Then
py = "N"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("哦") And Asc(Left(mystr, 1)) < Asc("啪") Then
py = "O"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("啪") And Asc(Left(mystr, 1)) < Asc("期") Then
py = "P"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("期") And Asc(Left(mystr, 1)) < Asc("然") Then
py = "Q"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("然") And Asc(Left(mystr, 1)) < Asc("撒") Then
py = "R"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("撒") And Asc(Left(mystr, 1)) < Asc("塌") Then
py = "S"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("塌") And Asc(Left(mystr, 1)) < Asc("挖") Then
py = "T"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("挖") And Asc(Left(mystr, 1)) < Asc("昔") Then
py = "W"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("昔") And Asc(Left(mystr, 1)) < Asc("压") Then
py = "X"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("压") And Asc(Left(mystr, 1)) < Asc("匝") Then
py = "Y"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("匝") Then
py = "Z"
Exit Function
End If
Else
If UCase(mystr) <= "Z" And UCase(mystr) >= "A" Then
py = UCase(Left(mystr, 1))
Else
py = mystr
End If
End If
End Function
Private Sub Command1_Click()
MsgBox py(Text1.Text)
End Sub
追问哥,这个好像也只能是首字母,能不能给一个用mid函数替代的,谢谢嘿嘿
热心网友
时间:2023-10-13 02:56
楼上的代码只能得到首字母,想要做个完美的,需要有个字典数组,每个汉字都有对应的拼音,如果是多音字,还需要根据上下文确定拼音。
热心网友
时间:2023-10-13 02:57
汉字转拼音缩写的函数(VB)
Public Function getPYChar(char As String) As String
Dim lChar As Long
lChar = 65536 + Asc(char)
If (lChar >= 45217 And lChar <= 45252) Then getPYChar = "A"
If (lChar >= 45253 And lChar <= 45760) Then getPYChar = "B"
If (lChar >= 47761 And lChar <= 46317) Then getPYChar = "C"
If (lChar >= 46318 And lChar <= 46825) Then getPYChar = "D"
If (lChar >= 46826 And lChar <= 47009) Then getPYChar = "E"
If (lChar >= 47010 And lChar <= 47296) Then getPYChar = "F"
If (lChar >= 47297 And lChar <= 47613) Then getPYChar = "G"
If (lChar >= 47614 And lChar <= 48118) Then getPYChar = "H"
If (lChar >= 48119 And lChar <= 49061) Then getPYChar = "J"
If (lChar >= 49062 And lChar <= 49323) Then getPYChar = "K"
If (lChar >= 49324 And lChar <= 49895) Then getPYChar = "L"
If (lChar >= 49896 And lChar <= 50370) Then getPYChar = "M"
If (lChar >= 50371 And lChar <= 50613) Then getPYChar = "N"
If (lChar >= 50614 And lChar <= 50621) Then getPYChar = "O"
If (lChar >= 50622 And lChar <= 50905) Then getPYChar = "P"
If (lChar >= 50906 And lChar <= 51386) Then getPYChar = "Q"
If (lChar >= 51387 And lChar <= 51445) Then getPYChar = "R"
If (lChar >= 51446 And lChar <= 52217) Then getPYChar = "S"
If (lChar >= 52218 And lChar <= 52697) Then getPYChar = "T"
If (lChar >= 52698 And lChar <= 52979) Then getPYChar = "W"
If (lChar >= 52980 And lChar <= 53640) Then getPYChar = "X"
If (lChar >= 53689 And lChar <= 54480) Then getPYChar = "Y"
If (lChar >= 54481 And lChar <= 52289) Then getPYChar = "Z"
End Function
Public Function getPY(str As String) As String
For i = 0 To Len(str) - 1
getPY = getPY & getPYChar(Mid(str, i + 1, 1))
Next
End Function
使用时:
msgbox(getPY(text1.Text))
热心网友
时间:2023-10-13 02:57
我自己做了一个ocx'控件,可以输入一大段中文后可输出它的拼音,但前提是电脑可以联网
调用方式
Private Sub Command1_Click()
py1.输入字符 = "你想要的文字"
MsgBox py1.输出字符
End Sub
控件下载地址我发给你,注意到百度信息里查收
vb6.0怎样实现汉字的拼音如text1输入“拼音”就msgbox(pinyin)
If Asc(Left(mystr, 1)) >= Asc("妈") And Asc(Left(mystr, 1)) < Asc("拿") Then py = "M"Exit Function End If If Asc(Left(mystr, 1)) >= Asc("拿") And Asc(Left(mystr, 1)) < Asc("哦") Then py = "N"Exit Function End If If Asc(Left(mystr, 1)) >=...
vb6.0中,我想在一个text里面只输入数字,不能输入其他的,比如汉字,符号...
Text1_Change是在Text1变化时触发,而不是“在其他地方一点鼠”时发生,另外:1、Text1的值一变化就MsgBox是很烦人的;2、IsNumeric(Text1.Text)不能完全符合设置,比如你输入12,然后按左箭头将光标移动1和2中间再输入字母E或D,是不会提示的,因为VB中默认1E2之类是数值的(科学计数法,1E2=100...
求问vb6.0中如何实现文本框中的段落数,字符数,字母数,和数字个数的统计...
MsgBox "行数:" & regEx.Execute(Text1.Text).CountEnd SubPrivate Sub Command2_Click() '统计数字 regEx.Pattern = "\d" MsgBox "数字:" & regEx.Execute(Text1.Text).CountEnd SubPrivate Sub Command3_Click() '统计字母 regEx.Pattern = "[a-z]" MsgBox "字母数:" &...
vb6.0怎样将保存的txt文件给数组赋值,并显示在text控件里?代码怎么写...
回答:留个Q我传你个代码
VB6.0一大堆问题,看问题补充,嫌麻烦的就看悬赏,100,回...
回答:文本框输入信息违反规则弹出消息举例 Private Sub Text1_LostFocus() '//当光标置内文本框得而失去焦点时 If Text1<>"XXX" Then MsgBox("输入错误!") End IfEnd Sub密码文本框就是把文本框的PasswordChar值设置成* 或者其他掩码作为遮盖 点个键弹出窗口是指快截键触发KeyDown事件 Private...
vb6.0中怎么强制规定文本框输入格式?比如text1中只能输入“898E 75600...
Private Sub Text1_KeyPress(KeyAscii As Integer)Select Case KeyAscii Case 101, 69, 32, 46, 13, 48 To 57 Case Else ' 其他数值。KeyAscii = 0 MsgBox "请正确填写……", 0, App.EXEName End Select End Sub
VB6中怎样按下一个按钮则弹出一个对话框~~要具体~~
1,输入对话框的用法:Private Sub Command1_Click()h = InputBox("请输入文本框中显示的值")Text1.Text = h End Sub 2,消息对话框 Private Sub Command1_Click()MsgBox ("你好")End Sub 3,通用对话框(打开对话框,另存为对话框,颜色对话框,字体对话框,打印对话框,帮助对话框)对用对话框...
vb6.0 怎样实现 WORD 的查找功能函数
这个不好实现。因为你用以自己的程序打不开Word文档(它的格式只有Word能打开),给Word发送信息让他查找的话,也没有那样的命令行参数。你最好把Word文档中的内容复制到你的程序文本框(例如Text1)中,输入查找内容的文本框Text2,命名查找按钮为Command1,然后代码可以这样写:Private Sub Command1_...
VB6.0中keypress事件使光标移到下一个文本框。
MsgBox "已经是最后一个", 0, "提示信息" '提示信息 t = 15 '变量值赋予控件数组最大值 Else Text1(t).SetFocus '否则把焦点转移到下一个 End If End If End Sub Private Sub Text1_GotFocus(Index As Integer) '文本框焦点事件 t = Index '记录当前获得焦点的控件数组 值 E...
vb6.0文本框TEXT1/text2只能输入大于10的数字
rem 失去焦点的时候自动检测Private Sub Text1_LostFocus() If Val(Text1.Text) <= 10 Then MsgBox "只能输入大于10的数字", vbCritical, "错误" Text1.Text = "" Text1.SetFocus End IfEnd Sub