有个功能函数代码,求将它转变为VB,急!(我只能给100分,不够可以另外给)
热门软件下载:
1,把从表hztopz中读汉字的拼音方法转为从文件中读
文件的格式:
[hztopz]
汉字=拼音
如:
[hztopz]
廖=liao
冠=guan
文件名:hztopz.ini
2,pb代码的两个函数为
f_zwtopy
f_getstringlist
3,转成vb函数名:
public function getpingying(byval strname as string ) as string
其中:参数strname 为一个或几个汉字,函数返回该汉字串的拼音
$pbexportheader$f_getstringlist.srf
global type f_getstringlist from function_object
end type
forward prototypes
global function string f_getstringlist (string a_string, integer a_pos, string a_lei)
end prototypes
global function string f_getstringlist (string a_string, integer a_pos, string a_lei);
long ll_pos,ll_num
string ls_temp[]
ll_num=0
a_string=trim(a_string)
do while 1=1
ll_pos=pos(a_string,a_lei,1)
if ll_pos=0 then
ll_num++
ls_temp[ll_num]=a_string
exit
else
ll_num++
ls_temp[ll_num]=mid(a_string,1,ll_pos -1)
a_string=mid(a_string,ll_pos+1,len(a_string) - ll_pos)
end if
loop
if a_pos>ll_num or a_pos<1 then
// f_mberr("位置错误!",1)
return ""
end if
return ls_temp[a_pos]
end function
$pbexportheader$f_zwtopy.srf
global type f_zwtopy from function_object
end type
forward prototypes
global function string f_zwtopy (string ar_zw)
end prototypes
global function string f_zwtopy (string ar_zw);if isnull(ar_zw) or len(ar_zw)=0 then return
string ls_hz,ls_mid
ls_hz=trim(ar_zw)
string ls_trim1,ls_trim2,ls_trim3,ls_trim4,ls_trim5,ls_trim
string ls_dan,ls_zpy
ls_dan=
ls_zpy=
ls_trim1=f_getstringlist(ls_hz,1," ")
ls_trim2=f_getstringlist(ls_hz,2," ")
ls_trim3=f_getstringlist(ls_hz,3," ")
ls_trim4=f_getstringlist(ls_hz,4," ")
ls_trim5=f_getstringlist(ls_hz,5," ")
ls_trim=trim(ls_trim1)+trim(ls_trim2)+trim(ls_trim3)+trim(ls_trim4)+trim(ls_trim5)
//messagebox(ls_trim,ls_trim)
long ll_long,ll_i
ll_long=len(ls_trim)
//messagebox(,string(ll_long))
for ll_i=1 to ll_long step 2
//messagebox(,string(ll_i))
ls_mid=mid (ls_trim, ll_i ,2 )
if isnull(ls_mid) or len(ls_mid)=0 then
else
//messagebox(,ls_mid)
select hztopz.pinying
into :ls_dan
from hztopz
where hztopz.zhonwen = :ls_mid ;
//messagebox(,ls_dan)
if isnull(ls_dan) or len(ls_dan)=0 then
messagebox(提示信息,汉字: 【+ls_mid+】 在拼音字库中不存在此拼音,请增
加!)
else
if isnull(ls_zpy) or len(ls_zpy)=0 then
ls_zpy=ls_dan
else
ls_zpy=ls_zpy+ls_dan
end if
end if
end if
next
//
return upper(ls_zpy)
end function
推荐阅读
读取ini文件就行了。
private declare function getprivateprofilestring lib "kernel32" alias "getprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as string, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as long
bytesback = getprivateprofilestring(section, key, "", lpreturnedstring, maxreturn, inifile)
up
to jinyou (人龙) :
不要转了,效率太低下了,文件越大,查询速度越慢,几乎不能忍受,鉴于文件格式的特殊性,可把它看成一个ini文件,因此,读取ini文件是个不错的想法,不过,对于特殊格式的文本来说,却不具有通用性。我通常用数据库思想处理它们。简单给你写了一个,你可以自己完善一下:
注意引用microsoft activex data objects 2.x library 对象 (一般为ado 2.5)
注意将拼音表放在app.path目录下
添加两个textbox,一个commandbutton
option explicit
dim conn as new adodb.connection, rs as new adodb.recordset
子函数shztopy,将单个字符转换成拼音
private function shztopy(sstr as string) as string
on error resume next
conn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & app.path & "\;" & _
"extended properties=""text;hdr=yes;fmt=delimited;"";"
rs.open "select * from pinyinbiao.txt where hanzi=" + sstr + "", conn, adopenstatic, adlockreadonly, adcmdtext
if not rs.bof and not rs.eof then
shztopy = rs.fields("pinyin")
else
shztopy = sstr
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
end function
private sub command1_click()
text2.text = hztopy(text1.text)
end sub
子函数hztopy,将字符串转换成拼音
private function hztopy(str as string) as string
on error resume next
dim lenstr as long, mytempstr as string
dim i as long
lenstr = len(str)
hztopy = ""
if lenstr = 0 then
msgbox "开什么玩笑,什么都没有,转换什么"
exit function
else
for i = 1 to lenstr
mytempstr = mid(str, i, 1)
hztopy = hztopy + shztopy(mytempstr)
next
end if
end function
需要注意的是程序执行时会寻找schema.ini文件,下面给你一个生成该文件的代码:
子过程,在app.path目录下生成schema.ini文件
private sub writeschemaini()
注意引用microsoft scripting runtime 对象
注意将拼音表放在app.path目录下
dim cfile as string
dim s as string, i as long
dim fsotest as new filesystemobject, file1 as file, ts as textstream
cfile = app.path + "\schema.ini"
set ts = fsotest.createtextfile(cfile, true)
ts.writeline "[pinyinbiao.txt]"
ts.writeline "colnameheader=false"
ts.writeline "format=delimited(=)"
ts.writeline "maxscanrows=0"
ts.writeline "characterset=oem"
ts.writeline "col1=hanzi char"
ts.write "col2=pinyin char"
set ts = nothing
set fsotest = nothing
end sub
相关评论