ducvudut > 13-05-23, 12:12 PM
Noname > 15-05-23, 08:58 AM
Public Function tong(intDigit As String) As Double
Dim strNaming As String
strNaming = Trim(intDigit)
Dim s1, s2 As String
Dim C, L, l1 As Integer
L = Len(strNaming)
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
s3 = s2
Dim i, giatri, duynhat
i = 1
giatri = 0
duynhat = 0
For i = 1 To L
L = L - 1
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
If s2 = "*" Or s2 = "/" Or s2 = "-" Or s2 = "(" Or s2 = ")" Then
duynhat = 1
Exit For
End If
Next
If duynhat = 0 Then
L = Len(strNaming)
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
s3 = s2
For i = 1 To L
L = L - 1
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
If s2 <> "+" Then
s3 = s2 & s3
End If
If s2 = "+" Then
giatri = giatri + Val(s3)
s3 = ""
End If
Next
giatri = giatri + Val(s3)
Else
L = Len(strNaming)
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
s3 = s2
For i = 1 To L
L = L - 1
s1 = Left(strNaming, L)
s2 = Right(s1, 1)
s3 = s2 & s3
Select Case s2
Case "+"
giatri = giatri + Val(s3)
Case "/"
giatri = giatri / Val(s3)
Case "-"
giatri = giatri - Val(s3)
Case "*"
giatri = giatri * Val(s3)
Case "("
Case ")"
End Select
Next
End If
tong = giatri
End Function