一个Form 一个TextBox 一个Label
这个修订後的程式是当使用者在TextBox中输入只包含0~9的数值後,在Label中就可看见被转换後的中文字,例如:1560890转成"壹佰伍拾陆万零捌佰玖拾"。程式限制为不可输入超过16个数字。
请建立一个新专案,并在表单中放入上述物件,再把以下程式码复制到表单的程式 码视窗,最後按下F5来执行。
PrivateSubForm_Load() Text1.MaxLength=16 Text1.Text="" Label1.Caption="" Label1.AutoSize=True Label1.BorderStyle=1 EndSub
PrivateSubText1_Change() Label1.Caption=CChinese(Text1.Text) EndSub
PrivateFunctionCChinese(StrEngAsString)AsString IfNotIsNumeric(StrEng)OrStrEngLike"*.*"OrStrEngLike"*-*"Then IfTrim(StrEng)<>""ThenMsgBox"无效的数字" CChinese="":ExitFunction EndIf DimintLenAsInteger,intCounterAsInteger DimstrChAsString,strTempChAsString DimstrSeqCh1AsString,strSeqCh2AsString DimstrEng2ChAsString strEng2Ch="零壹贰叁肆伍陆柒捌玖" strSeqCh1="拾佰仟拾佰仟拾佰仟拾佰仟" strSeqCh2="万亿兆" StrEng=CStr(CDec(StrEng)) intLen=Len(StrEng) ForintCounter=1TointLen strTempCh=Mid(strEng2Ch,Val(Mid(StrEng,intCounter,1)) 1,1) IfstrTempCh="零"AndintLen<>1Then IfMid(StrEng,intCounter 1,1)="0"Or(intLen-intCounter 1)Mod4=1Then strTempCh="" EndIf Else strTempCh=strTempCh&Trim(Mid(strSeqCh1,intLen-intCounter 1,1)) EndIf If(intLen-intCounter 1)Mod4=1Then strTempCh=strTempCh&Mid(strSeqCh2,(intLen-intCounter 1)\4 1,1) IfintCounter>3Then IfMid(StrEng,intCounter-3,4)="0000"ThenstrTempCh=Left(strTempCh,Len(strTempCh)-1) EndIf EndIf strCh=strCh&Trim(strTempCh) Next CChinese=strCh EndFunction->
Tags:文字 数字 阿拉 StrEng strTempCh EndIf 程式 intLen-intCounter
|
|