Doc so ban cap nhat 2011
description
Transcript of Doc so ban cap nhat 2011
Function Doc1(intDigit As Integer) As StringSelect Case intDigit Case 1 Doc1 = "moät" Case 2 Doc1 = "hai" Case 3 Doc1 = "ba" Case 4 Doc1 = "boán" Case 5 Doc1 = "naêm" Case 6 Doc1 = "saùu" Case 7 Doc1 = "baûy" Case 8 Doc1 = "taùm" Case 9 Doc1 = "chín" End Select
End Function
Function Doc2(intDigit1 As Integer, intDigit2 As Integer) As String
Dim strMuoi10 As StringDim strTens As StringDim strLam As StringDim strMuoi As StringstrLam = "laêm"Select Case intDigit1 Case 0 Doc2 = Doc1(intDigit2) Case 1 strMuoi10 = "möôøi" If intDigit2 = 0 Then Doc2 = strMuoi10 ElseIf intDigit2 <> 5 Then Doc2 = strMuoi10 & " " & Doc1(intDigit2) Else Doc2 = strMuoi10 & " " & strLam End If Case Else strMuoi = "möôi" If intDigit2 = 0 Then Doc2 = Doc1(intDigit1) & " " & strMuoi ElseIf intDigit2 <> 1 And intDigit2 <> 5 Then
Doc2 = Doc1(intDigit1) & " " & strMuoi & " " & Doc1(intDigit2) ElseIf intDigit2 = 1 Then Doc2 = Doc1(intDigit1) & " " & strMuoi & " moát" ElseIf intDigit2 = 5 Then Doc2 = Doc1(intDigit1) & " " & strMuoi & " " & strLam End IfEnd SelectEnd Function
Function Doc3(intDigit1 As Integer, intDigit2 As Integer, intDigit3 As Integer, Optional blnNhomDau As Boolean = False) As StringDim strTram As StringstrTram = "traêm"If intDigit1 = 0 And blnNhomDau = True Then Doc3 = Doc2(intDigit2, intDigit3)ElseIf intDigit1 = 0 And blnNhomDau = False Then If intDigit2 > 0 Then Doc3 = "khoâng traêm " & " " & Doc2(intDigit2, intDigit3) Else Doc3 = "khoâng traêm leû " & Doc1(intDigit3) End IfElseIf intDigit2 = 0 And intDigit3 = 0 Then Doc3 = Doc1(intDigit1) & " " & strTramElseIf intDigit2 = 0 And intDigit3 > 0 Then Doc3 = Doc1(intDigit1) & " " & strTram & " leû " & Doc1(intDigit3)Else Doc3 = Doc1(intDigit1) & " " & strTram & " " & Doc2(intDigit2, intDigit3)End IfEnd Function
Function DocSo(dblNumber As Double) As StringOn Error GoTo ErrDocSoDim strFormatNumber As StringDim intNumberLeftDigits As IntegerDim dblIntegerPart As DoubleDim intNumberParts As LongDim intRemainder As IntegerDim strIntegerPart As StringReDim arrDigitParts(1 To 6, 1 To 3) As IntegerReDim arrinWords(1 To 6, 1 To 2) As StringDim I As IntegerDim strThreeDigits As StringDim intFirstIndex As IntegerDim J As IntegerDim strIntegerPartInWords As StringDim strDecimalPart As StringDim strDecimalPartInWords As StringDim strNumberInWords As StringarrinWords(1, 2) = " ngaøn"arrinWords(2, 2) = " tyû"arrinWords(3, 2) = " trieäu"arrinWords(4, 2) = " ngaøn"
arrinWords(5, 2) = ""arrinWords(6, 2) = "xu"strFormatNumber = Format$(dblNumber, "#0.00")intNumberLeftDigits = Len(strFormatNumber) - 3'Debug.Print Format(dblNumber, "#,#0.00")If intNumberLeftDigits > 15 Then MsgBox "Soá coù nhieàu hôn 15 chöõ soá!" DocSo = "... ñoàng" Exit FunctionEnd IfIf dblNumber = 0 Then DocSo = "Khoâng ñoàng"Exit FunctionEnd IfdblIntegerPart = Int(dblNumber)strIntegerPart = Trim$(Str(dblIntegerPart))intRemainder = intNumberLeftDigits Mod 3If intRemainder = 0 Then intNumberParts = intNumberLeftDigits / 3ElseIf intRemainder = 1 Then intNumberParts = Int(intNumberLeftDigits / 3) + 1 strIntegerPart = "00" & strIntegerPart
Else intNumberParts = Int(intNumberLeftDigits / 3) + 1 strIntegerPart = "0" & strIntegerPartEnd IfintFirstIndex = 6 - intNumberPartsJ = 0For I = intFirstIndex To 5 J = J + 1 strThreeDigits = Mid$(strIntegerPart, (J - 1) * 3 + 1, 3) arrDigitParts(I, 1) = Val(Left$(strThreeDigits, 1)) arrDigitParts(I, 2) = Val(Mid$(strThreeDigits, 2, 1)) arrDigitParts(I, 3) = Val(Mid$(strThreeDigits, 3, 1))Next I
strDecimalPart = Right$(strFormatNumber, 2)
arrDigitParts(6, 2) = Val(Mid$(strDecimalPart, 1, 1)) arrDigitParts(6, 3) = Val(Mid$(strDecimalPart, 2, 1))
'For I = 1 To 6 'Debug.Print arrDigitParts(I, 1), arrDigitParts(I, 2), arrDigitParts(I, 3)'Next I
For I = 1 To 6
If arrDigitParts(I, 1) = 0 And arrDigitParts(I, 2) = 0 And arrDigitParts(I, 3) = 0 Then arrinWords(I, 1) = "zero"ElseIf I = intFirstIndex Then arrinWords(I, 1) = Doc3(arrDigitParts(I, 1), arrDigitParts(I, 2), arrDigitParts(I, 3), True)
Else arrinWords(I, 1) = Doc3(arrDigitParts(I, 1), arrDigitParts(I, 2), arrDigitParts(I, 3))
End If'Debug.Print arrinWords(I, 1), arrinWords(I, 2)
Next IstrIntegerPartInWords = ""For I = intFirstIndex To 5 If arrinWords(I, 1) <> "zero" Then strIntegerPartInWords = strIntegerPartInWords & " " & arrinWords(I, 1) & arrinWords(I, 2) End IfNext IIf arrinWords(1, 1) <> "zero" And arrinWords(2, 1) = "zero" Then strIntegerPartInWords = arrinWords(1, 1) & arrinWords(1, 2) & " " & arrinWords(2, 2) For I = 3 To 5 If arrinWords(I, 1) <> "zero" Then strIntegerPartInWords = strIntegerPartInWords & " " & arrinWords(I, 1) & arrinWords(I, 2) End If Next IEnd If
strIntegerPartInWords = strIntegerPartInWords & " ñoàng chaün."If arrDigitParts(6, 2) = 0 And arrDigitParts(6, 3) = 0 Then arrinWords(6, 1) = "zero"Else arrinWords(6, 1) = Doc3(arrDigitParts(6, 1), arrDigitParts(6, 2), arrDigitParts(6, 3), True)End If
'Debug.Print arrinWords(6, 1), arrinWords(6, 2)strDecimalPartInWords = arrinWords(6, 1) & " " & arrinWords(6, 2)If arrinWords(6, 1) <> "zero" Then strNumberInWords = Trim(strIntegerPartInWords & " vaø " & strDecimalPartInWords)Else strNumberInWords = Trim(strIntegerPartInWords)End IfDocSo = UCase$(Left$(strNumberInWords, 1)) & Mid$(strNumberInWords, 2)ErrDocSo:Exit FunctionEnd Function