Private Function Cal(Content) As Currency
'create by haier99_2000@sohu.com
On Error GoTo Calerr
If Trim(Content & "") & "" = "" Then
Cal = Null
Exit Function
End If
Content = Trim(Content)
If InStr(1, Content, "+", vbTextCompare) = 0 And InStr(1, Content, "-", vbTextCompare) = 0 And Len(Content) > 0 Then
Cal = CCur(Content)
Exit Function
End If
Dim Poss(10) As Integer, AddDec(10) As Boolean, jj, ContentSS, CalI As Integer
jj = 0
Poss(jj) = 1
For CalI = 1 To Len(Content)
ContentSS = Mid(Content, CalI, 1)
Select Case ContentSS
Case "+"
If CalI = 1 Then
Cal = CCur(Content)
Exit Function
End If
jj = jj + 1
Poss(jj) = CalI
AddDec(jj) = True
If Mid(Content, CalI + 1, 1) = "+" Or Mid(Content, CalI + 1, 1) = "-" Then
Content = Left(Content, CalI) & Right(Content, Len(Content) - CalI - 1)
End If
Case "-"
If CalI = 1 Then
Cal = CCur(Content)
Exit Function
End If
jj = jj + 1
Poss(jj) = CalI
AddDec(jj) = False
If Mid(Content, CalI + 1, 1) = "+" Or Mid(Content, CalI + 1, 1) = "-" Then
Content = Left(Content, CalI) & Right(Content, Len(Content) - CalI - 1)
End If
Case "."
If Mid(Content, CalI + 1, 1) = "." Then
Content = Left(Content, CalI) & Right(Content, Len(Content) - CalI - 1)
End If
Case Else
End Select
Next
Cal = 0
Cal = Cal + CCur(Mid(Content, 1, Poss(1) - 1))
If jj >= 2 Then
CalI = 2
Else
CalI = 0
End If
While CalI >= 2 And CalI <= jj
Cal = Cal + CCur(Mid(Content, Poss(CalI - 1), Poss(CalI) - Poss(CalI - 1)))
CalI = CalI + 1
Wend
Cal = Cal + CCur(Mid(Content, Poss(jj), Len(Content) - Poss(jj) + 1))
Exit Function
Calerr:
End
End Function