- Tham gia
- 8/6/06
- Bài viết
- 14,576
- Được thích
- 22,898
- Nghề nghiệp
- U80
PHP:
Option Explicit
Function ChaiVaLi(TonDau As String, Nhap As String, Xuat As Range) As String
Const Ch As String = "CHAI": Const Li As String = "LY"
Const KT As String = " ": Dim Cls As Range
Dim SoChai As Double, SoLi As Double, VTr As Byte
Tòn:
VTr = InStr(UCase$(TonDau), Ch)
If VTr > 0 Then
SoChai = SoChai + CByte(Trim(Left(TonDau, VTr - 1)))
TonDau = Mid(TonDau, VTr + 4, 9)
End If
VTr = InStr(UCase$(TonDau), Li)
If VTr > 0 Then
SoLi = SoLi + CByte(Trim(Left(TonDau, VTr - 1)))
End If
Nhap:
VTr = InStr(UCase$(Nhap), Ch)
If VTr > 0 Then
SoChai = SoChai + CByte(Trim(Left(Nhap, VTr - 1)))
Nhap = Mid(Nhap, VTr + 4, 9)
End If
VTr = InStr(UCase$(Nhap), Li)
If VTr > 0 Then
SoLi = SoLi + CByte(Trim(Left(Nhap, VTr - 1)))
End If
Xuát:
For Each Cls In Xuat
VTr = InStr(UCase$(Cls.Value), Ch)
If VTr > 0 Then
SoChai = SoChai - CByte(Trim(Left(Cls.Value, VTr - 1)))
End If
VTr = InStr(UCase$(Cls.Value), Li)
If VTr > 0 Then
SoLi = SoLi - CByte(Trim(Left(Cls.Value, VTr - 1)))
End If
If SoLi < 1 Then
SoChai = SoChai - 1
SoLi = SoLi + 5
End If
Next Cls
ChaiVaLi = CStr(SoChai) & KT & Ch & IIf(SoLi = 0, "", KT & CStr(SoLi) & KT & Li)
End Function