vui long cho mình hỏi, vì sao code đọc từ số sang chữ thường không đọc được chữ "lẻ", viết thêm vào cũng không được. vd; số 102 thì dịch ra là " một trăm hai đồng chẵn", còn thiếu chữ "lẻ". mọi người giúp mình với.
[FONT="] '*******************************[/FONT]
[FONT="] ' Main Function for vndnumber *[/FONT]
[FONT="] '*******************************[/FONT]
[FONT="] Public Function vndnumber(ByVal MyNumber)[/FONT]
[FONT="] Dim Dong, Temp[/FONT]
[FONT="] Dim DecimalPlace, Count[/FONT]
[FONT="] ReDim Place(9) As String[/FONT]
[FONT="] Place(2) = " Ngan "[/FONT]
[FONT="] Place(3) = " Trieu "[/FONT]
[FONT="] Place(4) = " Ty "[/FONT]
[FONT="] Place(5) = " Ngan Ty "[/FONT]
[FONT="] ' String representation of amount.[/FONT]
[FONT="] MyNumber = Trim(Str(MyNumber))[/FONT]
[FONT="] Count = 1[/FONT]
[FONT="] Do While MyNumber <> ""[/FONT]
[FONT="] Temp = vndGetHundreds(Right(MyNumber, 3))[/FONT]
[FONT="] If Temp <> "" Then Dong = Temp & Place(Count) & Dong[/FONT]
[FONT="] If Len(MyNumber) > 3 Then[/FONT]
[FONT="] MyNumber = Left(MyNumber, Len(MyNumber) - 3)[/FONT]
[FONT="] Else[/FONT]
[FONT="] MyNumber = ""[/FONT]
[FONT="] End If[/FONT]
[FONT="] Count = Count + 1[/FONT]
[FONT="] Loop[/FONT]
[FONT="] Select Case Dong[/FONT]
[FONT="] Case ""[/FONT]
[FONT="] Dong = "Khong Dong "[/FONT]
[FONT="] Case "One"[/FONT]
[FONT="] Dong = "Mot Dong Chan"[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] Dong = Dong & " Dong Chan"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] vndnumber = Dong[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] ' Converts a number from 100-999 into text *[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] Public Function vndGetHundreds(ByVal MyNumber)[/FONT]
[FONT="] Dim Result As String[/FONT]
[FONT="] If Val(MyNumber) = 0 Then Exit Function[/FONT]
[FONT="] MyNumber = Right("000" & MyNumber, 3)[/FONT]
[FONT="] ' Convert the hundreds place.[/FONT]
[FONT="] If Mid(MyNumber, 1, 1) <> "0" Then[/FONT]
[FONT="] Result = vndGetDigit(Mid(MyNumber, 1, 1)) & " Tram "[/FONT]
[FONT="] End If[/FONT]
[FONT="] ' Convert the tens and ones place.[/FONT]
[FONT="] If Mid(MyNumber, 2, 1) <> "0" Then[/FONT]
[FONT="] Result = Result & vndGetTens(Mid(MyNumber, 2))[/FONT]
[FONT="] Else[/FONT]
[FONT="] Result = Result & vndGetDigit(Mid(MyNumber, 3))[/FONT]
[FONT="] End If[/FONT]
[FONT="] vndGetHundreds = Result[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*********************************************[/FONT]
[FONT="] ' Converts a number from 10 to 99 into text. *[/FONT]
[FONT="] '*********************************************[/FONT]
[FONT="] Public Function vndGetTens(TensText)[/FONT]
[FONT="] Dim Result As String[/FONT]
[FONT="] Result = "" ' Null out the temporary function value.[/FONT]
[FONT="] If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...[/FONT]
[FONT="] Select Case Val(TensText)[/FONT]
[FONT="] Case 10: Result = "Muoi"[/FONT]
[FONT="] Case 11: Result = "Muoi Mot"[/FONT]
[FONT="] Case 12: Result = "Muoi Hai"[/FONT]
[FONT="] Case 13: Result = "Muoi Ba"[/FONT]
[FONT="] Case 14: Result = "Muoi Bon"[/FONT]
[FONT="] Case 15: Result = "Muoi Lam"[/FONT]
[FONT="] Case 16: Result = "Muoi Sau"[/FONT]
[FONT="] Case 17: Result = "Muoi Bay"[/FONT]
[FONT="] Case 18: Result = "Muoi Tam"[/FONT]
[FONT="] Case 19: Result = "Muoi Chin"[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] End Select[/FONT]
[FONT="] Else ' If value between 20-99...[/FONT]
[FONT="] Select Case Val(Left(TensText, 1))[/FONT]
[FONT="] Case 2: Result = "Hai Muoi "[/FONT]
[FONT="] Case 3: Result = "Ba Muoi "[/FONT]
[FONT="] Case 4: Result = "Bon Muoi "[/FONT]
[FONT="] Case 5: Result = "Nam Muoi "[/FONT]
[FONT="] Case 6: Result = "Sau Muoi "[/FONT]
[FONT="] Case 7: Result = "Bay Muoi "[/FONT]
[FONT="] Case 8: Result = "Tam Muoi "[/FONT]
[FONT="] Case 9: Result = "Chin Muoi "[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] End Select[/FONT]
[FONT="] Result = Result & vndGetDigit _[/FONT]
[FONT="] (Right(TensText, 1)) ' Retrieve ones place.[/FONT]
[FONT="] End If[/FONT]
[FONT="] vndGetTens = Result[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] ' Converts a number from 1 to 9 into text. *[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] Public Function vndGetDigit(Digit)[/FONT]
[FONT="] Select Case Val(Digit)[/FONT]
[FONT="] Case 1: vndGetDigit = "Mot"[/FONT]
[FONT="] Case 2: vndGetDigit = "Hai"[/FONT]
[FONT="] Case 3: vndGetDigit = "Ba"[/FONT]
[FONT="] Case 4: vndGetDigit = "Bon"[/FONT]
[FONT="] Case 5: vndGetDigit = "Nam"[/FONT]
[FONT="] Case 6: vndGetDigit = "Sau"[/FONT]
[FONT="] Case 7: vndGetDigit = "Bay"[/FONT]
[FONT="] Case 8: vndGetDigit = "Tam"[/FONT]
[FONT="] Case 9: vndGetDigit = "Chin"[/FONT]
[FONT="] Case Else: vndGetDigit = ""[/FONT]
[FONT="] End Select[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*******************************[/FONT]
[FONT="] ' Main Function for vndnumber *[/FONT]
[FONT="] '*******************************[/FONT]
[FONT="] Public Function vndnumber(ByVal MyNumber)[/FONT]
[FONT="] Dim Dong, Temp[/FONT]
[FONT="] Dim DecimalPlace, Count[/FONT]
[FONT="] ReDim Place(9) As String[/FONT]
[FONT="] Place(2) = " Ngan "[/FONT]
[FONT="] Place(3) = " Trieu "[/FONT]
[FONT="] Place(4) = " Ty "[/FONT]
[FONT="] Place(5) = " Ngan Ty "[/FONT]
[FONT="] ' String representation of amount.[/FONT]
[FONT="] MyNumber = Trim(Str(MyNumber))[/FONT]
[FONT="] Count = 1[/FONT]
[FONT="] Do While MyNumber <> ""[/FONT]
[FONT="] Temp = vndGetHundreds(Right(MyNumber, 3))[/FONT]
[FONT="] If Temp <> "" Then Dong = Temp & Place(Count) & Dong[/FONT]
[FONT="] If Len(MyNumber) > 3 Then[/FONT]
[FONT="] MyNumber = Left(MyNumber, Len(MyNumber) - 3)[/FONT]
[FONT="] Else[/FONT]
[FONT="] MyNumber = ""[/FONT]
[FONT="] End If[/FONT]
[FONT="] Count = Count + 1[/FONT]
[FONT="] Loop[/FONT]
[FONT="] Select Case Dong[/FONT]
[FONT="] Case ""[/FONT]
[FONT="] Dong = "Khong Dong "[/FONT]
[FONT="] Case "One"[/FONT]
[FONT="] Dong = "Mot Dong Chan"[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] Dong = Dong & " Dong Chan"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] vndnumber = Dong[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] ' Converts a number from 100-999 into text *[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] Public Function vndGetHundreds(ByVal MyNumber)[/FONT]
[FONT="] Dim Result As String[/FONT]
[FONT="] If Val(MyNumber) = 0 Then Exit Function[/FONT]
[FONT="] MyNumber = Right("000" & MyNumber, 3)[/FONT]
[FONT="] ' Convert the hundreds place.[/FONT]
[FONT="] If Mid(MyNumber, 1, 1) <> "0" Then[/FONT]
[FONT="] Result = vndGetDigit(Mid(MyNumber, 1, 1)) & " Tram "[/FONT]
[FONT="] End If[/FONT]
[FONT="] ' Convert the tens and ones place.[/FONT]
[FONT="] If Mid(MyNumber, 2, 1) <> "0" Then[/FONT]
[FONT="] Result = Result & vndGetTens(Mid(MyNumber, 2))[/FONT]
[FONT="] Else[/FONT]
[FONT="] Result = Result & vndGetDigit(Mid(MyNumber, 3))[/FONT]
[FONT="] End If[/FONT]
[FONT="] vndGetHundreds = Result[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*********************************************[/FONT]
[FONT="] ' Converts a number from 10 to 99 into text. *[/FONT]
[FONT="] '*********************************************[/FONT]
[FONT="] Public Function vndGetTens(TensText)[/FONT]
[FONT="] Dim Result As String[/FONT]
[FONT="] Result = "" ' Null out the temporary function value.[/FONT]
[FONT="] If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...[/FONT]
[FONT="] Select Case Val(TensText)[/FONT]
[FONT="] Case 10: Result = "Muoi"[/FONT]
[FONT="] Case 11: Result = "Muoi Mot"[/FONT]
[FONT="] Case 12: Result = "Muoi Hai"[/FONT]
[FONT="] Case 13: Result = "Muoi Ba"[/FONT]
[FONT="] Case 14: Result = "Muoi Bon"[/FONT]
[FONT="] Case 15: Result = "Muoi Lam"[/FONT]
[FONT="] Case 16: Result = "Muoi Sau"[/FONT]
[FONT="] Case 17: Result = "Muoi Bay"[/FONT]
[FONT="] Case 18: Result = "Muoi Tam"[/FONT]
[FONT="] Case 19: Result = "Muoi Chin"[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] End Select[/FONT]
[FONT="] Else ' If value between 20-99...[/FONT]
[FONT="] Select Case Val(Left(TensText, 1))[/FONT]
[FONT="] Case 2: Result = "Hai Muoi "[/FONT]
[FONT="] Case 3: Result = "Ba Muoi "[/FONT]
[FONT="] Case 4: Result = "Bon Muoi "[/FONT]
[FONT="] Case 5: Result = "Nam Muoi "[/FONT]
[FONT="] Case 6: Result = "Sau Muoi "[/FONT]
[FONT="] Case 7: Result = "Bay Muoi "[/FONT]
[FONT="] Case 8: Result = "Tam Muoi "[/FONT]
[FONT="] Case 9: Result = "Chin Muoi "[/FONT]
[FONT="] Case Else[/FONT]
[FONT="] End Select[/FONT]
[FONT="] Result = Result & vndGetDigit _[/FONT]
[FONT="] (Right(TensText, 1)) ' Retrieve ones place.[/FONT]
[FONT="] End If[/FONT]
[FONT="] vndGetTens = Result[/FONT]
[FONT="] End Function[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] ' Converts a number from 1 to 9 into text. *[/FONT]
[FONT="] '*******************************************[/FONT]
[FONT="] Public Function vndGetDigit(Digit)[/FONT]
[FONT="] Select Case Val(Digit)[/FONT]
[FONT="] Case 1: vndGetDigit = "Mot"[/FONT]
[FONT="] Case 2: vndGetDigit = "Hai"[/FONT]
[FONT="] Case 3: vndGetDigit = "Ba"[/FONT]
[FONT="] Case 4: vndGetDigit = "Bon"[/FONT]
[FONT="] Case 5: vndGetDigit = "Nam"[/FONT]
[FONT="] Case 6: vndGetDigit = "Sau"[/FONT]
[FONT="] Case 7: vndGetDigit = "Bay"[/FONT]
[FONT="] Case 8: vndGetDigit = "Tam"[/FONT]
[FONT="] Case 9: vndGetDigit = "Chin"[/FONT]
[FONT="] Case Else: vndGetDigit = ""[/FONT]
[FONT="] End Select[/FONT]
[FONT="] End Function[/FONT]
Lần chỉnh sửa cuối: