作者cellnucleus (sisi)
看板Office
标题[问题] VBA新手 布林值基本问题
时间Thu Jun 8 18:20:14 2023
下面是我看别人的程式
有个地方看不懂
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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.136.253.25 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1686219616.A.CAD.html
1F:推 windknife18: 他後面有更改 HasExp = True,如果你只是要使用 06/08 18:38
2F:→ windknife18: 不需要了解VBA 06/08 18:38
4F:推 waiter337: m>0的路线 HasExp 回圈回来後会变True 07/21 09:41