Private Sub Command1_Click()
Dim num, unit$(3), str$, t%, strlen%, endStr$, i%
num = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")
unit(1) = "拾": unit(2) = "佰": unit(3) = "仟"
Dim haveZero As Boolean
str = Val(Text1.Text) '①
If Len(str) > 4 Or Val(str) <= 0 Then
Text2.Text = "数据不合法,请重新输入"
Text1.SetFocus '② 获得文本框1的焦点
Exit Sub
End If
For i = 1 To Len(str) '③ 去掉左侧0,例如:002
If Mid(str, i, 1) <> "0" Then str = Mid(str, i, Len(str)): Exit For
Next i
For i = 1 To Len(str)
'④
t = Mid(str, i, 1)
If t = 0 Then
haveZero = True
Else
If haveZero Then
endStr = endStr + "零" + num(t) + unit(Len(str) - i)
Else
'⑤
endStr = endStr + num(t) + unit(Len(str) - i)
End If
End If
Next i
' ⑥
Text2.Text = endStr
End Sub