Các Bạn thử chép đoạn code này vào xem:Đây là hàm đổi số thành chữ
Public Function VND(BaoNhieu)
Dim KetQua, SoTien, Nhom, Chu, Dich, S1, S2, S3 As String
Dim I, J, Vitri As Byte, S As Double
Dim Hang, Doc, Dem
If BaoNhieu = 0 Then
KetQua = "Khäng âäöng"
Else
If Abs(BaoNhieu) >= 1E+15 Then
KetQua = " Säú låïn quaï ???"
Else
If BaoNhieu < 0 Then
KetQua = "Træì" & Space(1)
Else
KetQua = Space(0)
End If
SoTien = Format(Abs(BaoNhieu), "##############0.00")
SoTien = Right(Space(15) & SoTien, 18)
Hang = Array("None", "tràm", "mæåi", "gç âoï")
Doc = Array("None", "ngaìn tyí", "tyí", "triãûu", "ngaìn", "âäöng", "xu")
Dem = Array("None", "mäüt", "hai", "ba", "bäún", "nàm", "saïu", "baíy", "taïm", "chên")
For I = 1 To 6
Nhom = Mid(SoTien, I * 3 - 2, 3)
If Nhom <> Space(3) Then
Select Case Nhom
Case "000"
If I = 5 Then
Chu = "âäöng" & Space(1)
Else
Chu = Space(0)
End If
Case ".00"
Chu = "chàôn"
Case Else
S1 = Left(Nhom, 1)
S2 = Mid(Nhom, 2, 1)
S3 = Right(Nhom, 1)
Chu = Space(0)
Hang(3) = Doc(I)
For J = 1 To 3
Dich = Space(0)
S = Val(Mid(Nhom, J, 1))
If S > 0 Then
Dich = Dem(S) & Space(1) & Hang(J) & Space(1)
End If
Select Case J
Case 2 And S = 1
Dich = "mæåìi" & Space(1)
Case 3 And S = 0 And Nhom <> Space(2) & "0"
Dich = Hang(J) & Space(1)
Case 3 And S = 5 And S2 <> Space(1) And S2 <> "0"
Dich = "l" & Mid(Dich, 2)
Case 2 And S = 0 And S3 <> "0"
If (S1 >= "1" And S1 <= "9") Or (S1 = "0" And I = 4) Then
Dich = "leí" & Space(1)
End If
End Select
Chu = Chu & Dich
Next J
End Select
Vitri = InStr(1, Chu, "mæåi mäüt", 1)
If Vitri > 0 Then Mid(Chu, Vitri, 9) = "mæåi mäút"
KetQua = KetQua & Chu
End If
Next I
End If
End If
VND = UCase(Left(KetQua, 1)) & Mid(KetQua, 2)
End Function
-----------------
Public Function USD(WhatNumber)
Dim ToRead, NumString, Group, Word As String
Dim I, J As Byte, W, X, Y, Z As Double
Dim FristColum, SecondColum, ReadMetho
If WhatNumber = 0 Then
ToRead = "None"
Else
If Abs(WhatNumber) >= 1E+15 Then
ToRead = "Too long number ???"
Else
FristColum = Array("None", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen")
SecondColum = Array("None", "None", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
ReadMetho = Array("None", "trillion", "billion", "million", "thousand", "dollars", "cents")
If WhatNumber < 0 Then
ToRead = "Minus" & Space(1)
Else
ToRead = Space(0)
End If
NumString = Format(Abs(WhatNumber), "##############0.00")
NumString = Right(Space(15) & NumString, 18)
For I = 1 To 6
Group = Mid(NumString, I * 3 - 2, 3)
If Group <> Space(3) Then
Select Case Group
Case "000"
If I = 5 And Abs(WhatNumber) > 1 Then
Word = "dollars" & Space(1)
Else
Word = Space(0)
End If
Case ".00"
Word = "only"
Case Else
X = Val(Left(Group, 1))
Y = Val(Mid(Group, 2, 1))
Z = Val(Right(Group, 1))
W = Val(Right(Group, 2))
If X = 0 Then
Word = Space(0)
Else
Word = FristColum(X) & Space(1) & "hundred" & Space(1)
If W > 0 And W < 21 Then
Word = Word & "and" & Space(1)
End If
End If
If I = 6 And Abs(WhatNumber) > 1 Then
Word = "and" & Space(1) & Word
End If
If W < 20 And W > 0 Then
Word = Word & FristColum(W) & Space(1)
Else
If W >= 20 Then
Word = Word & SecondColum(Y) & Space(1)
If Z > 0 Then
Word = Word & FristColum(Z) & Space(1)
End If
End If
End If
Word = Word & ReadMetho(I) & Space(1)
End Select
ToRead = ToRead & Word
End If
Next I
End If
End If
USD = UCase(Left(ToRead, 1)) & Mid(ToRead, 2)
End Function
-------------
Public Function VND_US(WhatNumber)
Dim ToRead, NumString, Group, Word As String
Dim I, J As Byte, W, X, Y, Z As Double
Dim FristColum, SecondColum, ReadMetho
If WhatNumber = 0 Then
ToRead = "None"
Else
If Abs(WhatNumber) >= 1E+15 Then
ToRead = "! Too long number ???"
Else
FristColum = Array("None", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen")
SecondColum = Array("None", "None", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
ReadMetho = Array("None", "trillion", "billion", "million", "thousand", "Vietnamese dong", "xu")
If WhatNumber < 0 Then
ToRead = "Minus" & Space(1)
Else
ToRead = Space(0)
End If
NumString = Format(Abs(WhatNumber), "##############0.00")
NumString = Right(Space(15) & NumString, 18)
For I = 1 To 6
Group = Mid(NumString, I * 3 - 2, 3)
If Group <> Space(3) Then
Select Case Group
Case "000"
If I = 5 And Abs(WhatNumber) > 1 Then
Word = "Vietnamese dong" & Space(1)
Else
Word = Space(0)
End If
Case ".00"
Word = "only"
Case Else
X = Val(Left(Group, 1))
Y = Val(Mid(Group, 2, 1))
Z = Val(Right(Group, 1))
W = Val(Right(Group, 2))
If X = 0 Then
Word = Space(0)
Else
Word = FristColum(X) & Space(1) & "hundred" & Space(1)
If W > 0 And W < 21 Then
Word = Word & "and" & Space(1)
End If
End If
If I = 6 And Abs(WhatNumber) > 1 Then
Word = "and" & Space(1) & Word
End If
If W < 20 And W > 0 Then
Word = Word & FristColum(W) & Space(1)
Else
If W >= 20 Then
Word = Word & SecondColum(Y) & Space(1)
If Z > 0 Then
Word = Word & FristColum(Z) & Space(1)
End If
End If
End If
Word = Word & ReadMetho(I) & Space(1)
End Select
ToRead = ToRead & Word
End If
Next I
End If
End If
VND_US = UCase(Left(ToRead, 1)) & Mid(ToRead, 2)
End Function
______
Font: VNtimes new roman
=vnd(): Trả về VND tiếng việt
=usd(): Trả về USD tiếng anh
=vnd_us(): Trả về VND tiếng anh
Mình đang cần 1 đoạn code trả về USD tiếng việt. Bác nào có thể chỉ bảo cho mình với
Public Function VND(BaoNhieu)
Dim KetQua, SoTien, Nhom, Chu, Dich, S1, S2, S3 As String
Dim I, J, Vitri As Byte, S As Double
Dim Hang, Doc, Dem
If BaoNhieu = 0 Then
KetQua = "Khäng âäöng"
Else
If Abs(BaoNhieu) >= 1E+15 Then
KetQua = " Säú låïn quaï ???"
Else
If BaoNhieu < 0 Then
KetQua = "Træì" & Space(1)
Else
KetQua = Space(0)
End If
SoTien = Format(Abs(BaoNhieu), "##############0.00")
SoTien = Right(Space(15) & SoTien, 18)
Hang = Array("None", "tràm", "mæåi", "gç âoï")
Doc = Array("None", "ngaìn tyí", "tyí", "triãûu", "ngaìn", "âäöng", "xu")
Dem = Array("None", "mäüt", "hai", "ba", "bäún", "nàm", "saïu", "baíy", "taïm", "chên")
For I = 1 To 6
Nhom = Mid(SoTien, I * 3 - 2, 3)
If Nhom <> Space(3) Then
Select Case Nhom
Case "000"
If I = 5 Then
Chu = "âäöng" & Space(1)
Else
Chu = Space(0)
End If
Case ".00"
Chu = "chàôn"
Case Else
S1 = Left(Nhom, 1)
S2 = Mid(Nhom, 2, 1)
S3 = Right(Nhom, 1)
Chu = Space(0)
Hang(3) = Doc(I)
For J = 1 To 3
Dich = Space(0)
S = Val(Mid(Nhom, J, 1))
If S > 0 Then
Dich = Dem(S) & Space(1) & Hang(J) & Space(1)
End If
Select Case J
Case 2 And S = 1
Dich = "mæåìi" & Space(1)
Case 3 And S = 0 And Nhom <> Space(2) & "0"
Dich = Hang(J) & Space(1)
Case 3 And S = 5 And S2 <> Space(1) And S2 <> "0"
Dich = "l" & Mid(Dich, 2)
Case 2 And S = 0 And S3 <> "0"
If (S1 >= "1" And S1 <= "9") Or (S1 = "0" And I = 4) Then
Dich = "leí" & Space(1)
End If
End Select
Chu = Chu & Dich
Next J
End Select
Vitri = InStr(1, Chu, "mæåi mäüt", 1)
If Vitri > 0 Then Mid(Chu, Vitri, 9) = "mæåi mäút"
KetQua = KetQua & Chu
End If
Next I
End If
End If
VND = UCase(Left(KetQua, 1)) & Mid(KetQua, 2)
End Function
-----------------
Public Function USD(WhatNumber)
Dim ToRead, NumString, Group, Word As String
Dim I, J As Byte, W, X, Y, Z As Double
Dim FristColum, SecondColum, ReadMetho
If WhatNumber = 0 Then
ToRead = "None"
Else
If Abs(WhatNumber) >= 1E+15 Then
ToRead = "Too long number ???"
Else
FristColum = Array("None", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen")
SecondColum = Array("None", "None", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
ReadMetho = Array("None", "trillion", "billion", "million", "thousand", "dollars", "cents")
If WhatNumber < 0 Then
ToRead = "Minus" & Space(1)
Else
ToRead = Space(0)
End If
NumString = Format(Abs(WhatNumber), "##############0.00")
NumString = Right(Space(15) & NumString, 18)
For I = 1 To 6
Group = Mid(NumString, I * 3 - 2, 3)
If Group <> Space(3) Then
Select Case Group
Case "000"
If I = 5 And Abs(WhatNumber) > 1 Then
Word = "dollars" & Space(1)
Else
Word = Space(0)
End If
Case ".00"
Word = "only"
Case Else
X = Val(Left(Group, 1))
Y = Val(Mid(Group, 2, 1))
Z = Val(Right(Group, 1))
W = Val(Right(Group, 2))
If X = 0 Then
Word = Space(0)
Else
Word = FristColum(X) & Space(1) & "hundred" & Space(1)
If W > 0 And W < 21 Then
Word = Word & "and" & Space(1)
End If
End If
If I = 6 And Abs(WhatNumber) > 1 Then
Word = "and" & Space(1) & Word
End If
If W < 20 And W > 0 Then
Word = Word & FristColum(W) & Space(1)
Else
If W >= 20 Then
Word = Word & SecondColum(Y) & Space(1)
If Z > 0 Then
Word = Word & FristColum(Z) & Space(1)
End If
End If
End If
Word = Word & ReadMetho(I) & Space(1)
End Select
ToRead = ToRead & Word
End If
Next I
End If
End If
USD = UCase(Left(ToRead, 1)) & Mid(ToRead, 2)
End Function
-------------
Public Function VND_US(WhatNumber)
Dim ToRead, NumString, Group, Word As String
Dim I, J As Byte, W, X, Y, Z As Double
Dim FristColum, SecondColum, ReadMetho
If WhatNumber = 0 Then
ToRead = "None"
Else
If Abs(WhatNumber) >= 1E+15 Then
ToRead = "! Too long number ???"
Else
FristColum = Array("None", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen")
SecondColum = Array("None", "None", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
ReadMetho = Array("None", "trillion", "billion", "million", "thousand", "Vietnamese dong", "xu")
If WhatNumber < 0 Then
ToRead = "Minus" & Space(1)
Else
ToRead = Space(0)
End If
NumString = Format(Abs(WhatNumber), "##############0.00")
NumString = Right(Space(15) & NumString, 18)
For I = 1 To 6
Group = Mid(NumString, I * 3 - 2, 3)
If Group <> Space(3) Then
Select Case Group
Case "000"
If I = 5 And Abs(WhatNumber) > 1 Then
Word = "Vietnamese dong" & Space(1)
Else
Word = Space(0)
End If
Case ".00"
Word = "only"
Case Else
X = Val(Left(Group, 1))
Y = Val(Mid(Group, 2, 1))
Z = Val(Right(Group, 1))
W = Val(Right(Group, 2))
If X = 0 Then
Word = Space(0)
Else
Word = FristColum(X) & Space(1) & "hundred" & Space(1)
If W > 0 And W < 21 Then
Word = Word & "and" & Space(1)
End If
End If
If I = 6 And Abs(WhatNumber) > 1 Then
Word = "and" & Space(1) & Word
End If
If W < 20 And W > 0 Then
Word = Word & FristColum(W) & Space(1)
Else
If W >= 20 Then
Word = Word & SecondColum(Y) & Space(1)
If Z > 0 Then
Word = Word & FristColum(Z) & Space(1)
End If
End If
End If
Word = Word & ReadMetho(I) & Space(1)
End Select
ToRead = ToRead & Word
End If
Next I
End If
End If
VND_US = UCase(Left(ToRead, 1)) & Mid(ToRead, 2)
End Function
______
Font: VNtimes new roman
=vnd(): Trả về VND tiếng việt
=usd(): Trả về USD tiếng anh
=vnd_us(): Trả về VND tiếng anh
Mình đang cần 1 đoạn code trả về USD tiếng việt. Bác nào có thể chỉ bảo cho mình với