Hello All,
I am quite bad at writing VBA codes but quite good at finding something already done and changing it to fit what I want to do.
I converted below code from Turkish to convert numbers to verbal statments that write for example:
SAY #ONEHUNDREDTWENTYTHOUSANDFOURHUNDREDTHIRTYTWOUSD# ONLY
However, in Turkish for example, twelve is a combination of number ten and two; and it is written like that as well like tentwo. So, my code below returns interesting things for values below 20K like:
SAY #TENONETHOUSANDNINEHUNDREDTENEIGHTUSDFORTYCENTS# ONLY (notice TENONE )
I need help with this, how can I add numbers from eleven to nineteen in this code (and I just realized the code is in Turkish as well, I hope someone can help me)?
Function USD(sayi)
x = InStr(1, sayi, ",")
If x > 0 Then
Lira = "SAY #" & yaz$(Mid(sayi, 1, x - 1)) & "USD"
TempKurus = Mid(sayi, x + 1, 98)
If Len(TempKurus) = 1 Then TempKurus = TempKurus * 10
If Len(TempKurus) > 2 Then TempKurus = Mid(TempKurus, 1, 2)
Kurus = yaz$(TempKurus) & "CENTS# ONLY"
Else
Lira = "SAY #" & yaz$(sayi) & "USD# ONLY"
End If
USD = Lira & Kurus
End Function
Function yaz$(sayi)
Dim b$(9)
Dim y$(9)
Dim m$(4)
Dim v$(15)
Dim c$(3)
b$(0) = ""
b$(1) = "ONE"
b$(2) = "TWO"
b$(3) = "THREE"
b$(4) = "FOUR"
b$(5) = "FIVE"
b$(6) = "SIX"
b$(7) = "SEVEN"
b$(8) = "EIGHT"
b$(9) = "NINE"
y$(0) = ""
y$(1) = "TEN"
y$(2) = "TWENTY"
y$(3) = "THIRTY"
y$(4) = "FORTY"
y$(5) = "FIFTY"
y$(6) = "SIXTY"
y$(7) = "SEVENTY"
y$(8) = "EIGHTY"
y$(9) = "NINETY"
m$(0) = "TRILLION"
m$(1) = "BILLION"
m$(2) = "MILLION"
m$(3) = "THOUSAND"
m$(4) = ""
a$ = Str(sayi)
If Left$(a$, 1) = "" Then pozitif = 1 Else pozitif = 0
a$ = Right$(a$, Len(a$) - 1)
For x = 1 To Len(a$)
If (Asc(Mid$(a$, x, 1)) > Asc("9")) Or (Asc(Mid$(a$, x, 1)) < Asc("0")) Then GoTo hata
Next x
If Len(a$) > 15 Then GoTo hata
a$ = String(15 - Len(a$), "0") + a$
For x = 1 To 15
v(x) = Val(Mid$(a$, x, 1))
Next x
a$ = ""
For x = 0 To 4
c(1) = v((x * 3) + 1)
c(2) = v((x * 3) + 2)
c(3) = v((x * 3) + 3)
If c(1) = 0 Then
e$ = ""
ElseIf c(1) = 1 Then
e$ = "ONEHUNDRED"
Else
e$ = b$(c(1)) + "HUNDRED"
End If
e$ = e$ + y$(c(2)) + b$(c(3))
If e$ <> "" Then e$ = e$ + m$(x)
If (x = 3) And (e$ = "ONETHOUSAND") Then e$ = "THOUSAND"
s$ = s$ + e$
Next x
If s$ = "" Then s$ = "ZERO"
If pozitif = 0 Then s$ = "" + s$
yaz$ = s$
GoTo tamam
hata: yaz$ = "hata"
tamam:
End Function
Bookmarks