下面是我看別人的程式
有個地方看不懂
If HasExp = False Then
temp = NumChar & temp
Else
temp = NumChar & Mid(temp, 2)
If NumChar = 0 Then temp = 1 & Mid(temp, 2)
End If
如果前面都沒有宣告布林值HasExp為正或負
應該就是基本值是false
這樣不就是執行上面這段就會一直跑去
HasExp = False的部分嗎??
那寫else要幹嘛
抱歉小弟沒程式基礎 查很久不太清楚
下面是完整代碼
Public Function CNToNum(sDBNum)
'=============================
'中文大小写转阿拉伯数字函数
'中文大写人民币数字转阿拉伯数字
'by mzbao
'=============================
Dim sCNnum$, sCNExp$, ExpArr, temp, i%, sChar$, NumChar$
Dim m%, n%, rNum%, d%
Dim LastExp%, Exp%, sFlag$, HasExp As Boolean
sCNnum = "〇零一二三四五六七八九壹贰叁肆伍陆柒捌玖00123456789123456789"
sCNExp = ",十,百,千,万,亿,兆,拾,佰,仟,萬,1,2,3,4,8,12,1,2,3,4"
ExpArr = Split(sCNExp, ",")
For i = 1 To 3
sDBNum = Replace(sDBNum, Mid("整角分", i, 1), "")
sDBNum = Replace(sDBNum, Mid("点元圆", i, 1), ".")
sDBNum = Replace(sDBNum, Mid("○", i, 1), "零")
Next i
sDBTxt = sDBNum
For i = Len(sDBTxt) To 1 Step -1
sChar = Mid(sDBTxt, i, 1)
m = InStr(sCNnum, sChar)
If m > 0 Then
If rNum = 0 Then rNum = i
If m <= 20 Then
NumChar = Mid(sCNnum, m + 20, 1)
Else
NumChar = sChar
End If
If HasExp = False Then
temp = NumChar & temp
Else
temp = NumChar & Mid(temp, 2)
If NumChar = 0 Then temp = 1 & Mid(temp, 2)
End If
HasExp = False
If Exp > LastExp Then LastExp = 0
Else
n = InStr(sCNExp, sChar)
If n > 0 Then
Exp = ExpArr(n / 2 + 10)
If InStr(",4,8,12,", "," & Exp & ",") Then
If LastExp >= Exp Then
LastExp = LastExp + Exp: Exp = 0
Else
LastExp = Exp: Exp = 0
End If
End If
sFlag = String(Exp + LastExp + 1 + d, "0")
temp = Format(1 * temp, sFlag)
HasExp = True
End If
If sChar = "." Then
If i < rNum Then d = rNum - i
End If
End If
Next
If Left(temp, 1) = "0" And Len(temp) > 1 And Len(temp) > d + 1 Then temp = 1
& Mid(temp, 2)
CNToNum = 1 * temp / 10 ^ d
End Function