怎么做好市场宣传和推广,wordpress优化速度,网站建设公司有哪些,做网站框架浏览时怎么变长写在前面
这是PB案例学习笔记系列文章的第22篇#xff0c;该系列文章适合具有一定PB基础的读者。
通过一个个由浅入深的编程实战案例学习#xff0c;提高编程技巧#xff0c;以保证小伙伴们能应付公司的各种开发需求。
文章中设计到的源码#xff0c;小凡都上传到了gite…写在前面
这是PB案例学习笔记系列文章的第22篇该系列文章适合具有一定PB基础的读者。
通过一个个由浅入深的编程实战案例学习提高编程技巧以保证小伙伴们能应付公司的各种开发需求。
文章中设计到的源码小凡都上传到了gitee代码仓库https://gitee.com/xiezhr/pb-project-example.git 需要源代码的小伙伴们可以自行下载查看后续文章涉及到的案例代码也都会提交到这个仓库【pb-project-example】
如果对小伙伴有所帮助希望能给一个小星星⭐支持一下小凡。
一、小目标
上一个案例中我们将小写金额转换为大写金额这一个案例中我们将制作一个语音播报金额的小应用。
这个在日常开发中也很常见尤其是在收费结算应用中。最终实现效果如下 金额语音播报 二、实现思路
首先我们需要准备 零、壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、整
的.wav格式的语音文件。然后通过WINMM.dll外部动态库的sandPlaySoundA()和waveOutGetNumDevs()
联合起来播放语音文件
三、创建程序基本框架
① 新建examplework工作区
② 新建exampleapp应用
③ 新建w_main窗口将其Title属性值设置成“朗读款项金额”
由于篇幅原因以上步骤这儿就不展开了忘记了的小伙伴翻一翻该系列文章的第一篇
④ 在w_main窗口上放置控件
在窗口上添加3个StaticEdit控件1个singleLineEdit控件和2个CommandButton。将其分别命名为st_1、st_2、st_3
sle_1、sle_2、cb_1和cb_2。 调整各个控件布局后如下 ⑤ 保存窗口
四、编写代码
① 定义本地外部扩展函数
在w_main的Declare Local External Function 选项卡中添加如下代码
Function boolean sndPlaySoundA(string SoundName, uint Flags) Library WINMM.DLL
Function uint waveOutGetNumDevs ()Library WINMM.DLL② 在W_main窗口的Function List 选项卡中添加Playsound(string as_filename,integer ai_option) return integer函数
代码如下
uint lui_numdevslui_numdevs WaveOutGetNumDevs()
If lui_numdevs 0 Then sndPlaySoundA(as_filename,ai_option)return 1
Elsereturn -1
End If③ 在w_main窗口的Function List 选项卡中添加xx2dx(decimal ls) return string函数
代码如下
string dx_sz,dx_dw,str_int,str_dec,dx_str,fu,a,b,b2,c,d,result
long num_int,num_dec,len_int,i,a_int,ppdx_sz 零壹贰叁肆伍陆柒捌玖
dx_dw 万仟佰拾亿仟佰拾万仟佰拾元 //处理小于零情况
if ls0 thenls ls*(-1) fu 负
else fu
end if //取得整数及整数串
dx_str string(ls)
if (ls0) and (ls1) then dx_str 0dx_str
pp pos(dx_str,.)
if pp0 then str_int mid(dx_str,1,pos(dx_str,.)-1)
elsestr_int dx_str
end if
num_int long(str_int) //取得小数及小数串
if (ls0) and (ls1) then num_dec ls * 100
elsenum_dec (ls - num_int) * 100
end if
str_dec string(num_dec)
len_int len(str_int)
dx_str //转换整整部分
for i 1 to len_int //a为小写数字字符b为对应的大写字符c为对应大写单位d为当前大写字符串的最后一个汉字a mid(str_int,i,1) a_int long(a) b mid(dx_sz,(a_int*2)1,2) c mid(dx_dw,((13 - len_int i - 1)*21),2) if dx_str thendmid(dx_str,len(dx_str)-1,2)elsed end if if (b零) and ((d零) or (bb2) or (c元) or (c万) or (c亿)) then b if (a0) and (c元) and (c万) and (c亿) then c if ((c元) or (c万) or (c亿)) and (d零) and (a0) thendx_str mid(dx_str,1,len(dx_str)-2) dmid(dx_str,len(dx_str)-1,2) if ((c元) and (d万)) or ((c万) and (d亿)) then c end if dx_str dx_str b c b2 b
next//处理金额小于1的情况if len(dx_str) 2 then dx_str //转换小数部分if (num_dec10) and (ls0) thena_int long(str_dec) b mid(dx_sz,(a_int*21),2) if num_dec 0 then dx_str dx_str 整 if num_dec 0 then dx_str dx_str 零b分 end ifif num_dec 10 thena_int long(mid(str_dec,1,1)) a mid(dx_sz,(a_int*21),2) a_int long(mid(str_dec,2,1)) b mid(dx_sz,(a_int*21),2) if a零 then a a角 if b 零 thenb b分else b end ifdx_str dx_str a b end ifif ls 0 then dx_str 零元整 dx_str fudx_str result dx_str return result④ 将事先准备好的.wav格式声音放到项目temp目录下 语音包小凡已经上传的百度网盘了需要的小伙伴自行下载哈
链接https://pan.baidu.com/s/17sPGYC21fvzw4ebgXll74A?pwd8888 提取码8888
⑤在w_main窗口的cb_1按钮的Clicked事件 中添加如下代码
integer i,count
string ls_current_path
//获取项目当前路径
ls_current_path GetCurrentDirectory()st_3.text xx2dx(dec(sle_1.text))count len(st_3.text)for i 1 to count step 2CHOOSE CASE mid(st_3.text,i,2)CASE 零playsound(ls_current_path\temp\0.wav,0) CASE 壹playsound(ls_current_path\temp\1.wav,0) CASE 贰playsound(ls_current_path\temp\2.wav,0) CASE 叁playsound(ls_current_path\temp\3.wav,0) CASE 肆playsound(ls_current_path\temp\4.wav,0) CASE 伍playsound(ls_current_path\temp\5.wav,0) CASE 陆playsound(ls_current_path\temp\6.wav,0) CASE 柒playsound(ls_current_path\temp\7.wav,0) CASE 捌playsound(ls_current_path\temp\8.wav,0) CASE 玖playsound(ls_current_path\temp\9.wav,0) CASE 拾playsound(ls_current_path\temp\十.wav,0) CASE 佰playsound(ls_current_path\temp\佰.wav,0) CASE 仟playsound(ls_current_path\temp\仟.wav,0) CASE 万playsound(ls_current_path\temp\万.wav,0) CASE 亿playsound(ls_current_path\temp\亿.wav,0) CASE 元playsound(ls_current_path\temp\元.wav,0) CASE 角playsound(ls_current_path\temp\角.wav,0) CASE 分playsound(ls_current_path\temp\分.wav,0) CASE 整playsound(ls_current_path\temp\整.wav,0) END CHOOSE
next⑥ 在cb_2退出按钮的Clicked事件中添加如下代码
close(parent)⑦ 在开发界面左边的System Tree窗口中双击exampleapp应用对象并在其Open事件中添加如下代码
open(w_main)五、运行程序
代码写完了来检验下我们的劳动成果。 金额语音播报 本期内容到这儿就结束了 ★,°:.☆(▽)/$:.°★ 。希望对您有所帮助
我们下期再见 ヾ(•ω•)o (●’◡’●)