Function GetalInLetters(Dbl_Getal As Double)
Dim Str_Cent, Str_Duizend, Str_Eenheid, Str_Getal, str_Miljoen, Str_En, Str_Res As String
Dim intA As Integer
Str_Cent = " cent"
Str_Eenheid = " Euro"
Str_Duizend = "duizend "
str_Miljoen = " miljoen "
Str_En = " en "
If Dbl_Getal > 999999999.99 Then
MsgBox "Getal buiten bereik"
Exit Function
End If
Str_Getal = Format$(Dbl_Getal, "000000000.00")
'Miljoen
intA = Val(Left(Str_Getal, 3))
If intA > 0 Then
Str_Res = GroepInLetters(intA) & " " & Trim(str_Miljoen) & " "
End If
'Duizend
intA = Val(Mid(Str_Getal, 4, 3))
'We zeggen 'duizend' niet 'een duizend'
If intA > 1 Then Str_Res = Str_Res & GroepInLetters(intA)
If intA > 0 Then Str_Res = Str_Res & Trim(Left$(Str_Duizend, 8)) & " "
'Honderd
intA = Val(Mid(Str_Getal, 7, 3))
If intA > 0 Then
Str_Res = Str_Res & GroepInLetters(intA)
End If
If Dbl_Getal >= 1 Then Str_Res = Str_Res & Str_Eenheid
intA = Val(Right(Str_Getal, 2))
If intA > 0 Then
Str_Res = Str_Res & " " & GroepInLetters(intA) & Str_Cent
End If
GetalInLetters = UCase(Mid$(Str_Res, 1, 1)) & LCase(Mid$(Str_Res, 2))
End Function
Public Function GroepInLetters(Int_Getal As Integer)
Dim Str_Eenheid, Str_Tiental, Str_Twin_Negentig, Str_Honderd, Str_En, Str_EnTrema, Str_Getal, str_A As String
Dim By_Eh As Byte, By_Tt As Byte, By_Ht As Byte
If IsMissing(Int_Getal) Then Int_Getal = 123456789.12
If Int_Getal > 999 Or Int_Getal < 0 Then
GroepInLetters = "Getal buiten het bereik !"
Exit Function
End If
Str_Getal = Format$(Int_Getal, "000")
Str_Eenheid = "EEN " & _
"TWEE " & _
"DRIE " & _
"VIER " & _
"VIJF " & _
"ZES " & _
"ZEVEN " & _
"ACHT " & _
"NEGEN "
Str_Tiental = "TIEN " & _
"ELF " & _
"TWAALF " & _
"DERTIEN " & _
"VEERTIEN " & _
"VIJFTIEN " & _
"ZESTIEN " & _
"ZEVENTIEN" & _
"ACHTTIEN " & _
"NEGENTIEN"
Str_Twin_Negentig = "TWINTIG " & _
"DERTIG " & _
"VEERTIG " & _
"VIJFTIG " & _
"ZESTIG " & _
"ZEVENTIG " & _
"TACHTIG " & _
"NEGENTIG "
Str_Honderd = "HONDERD"
Str_En = " en "
Str_EnTrema = " ën "
'Str_EnNoSpace = "en"
By_Eh = Val(Mid$(Str_Getal, 3, 1))
By_Tt = Val(Mid$(Str_Getal, 2, 1)):
By_Ht = Val(Mid$(Str_Getal, 1, 1))
If By_Ht > 0 Then
str_A = str_A & IIf(By_Ht > 1, Trim(Mid$(Str_Eenheid, (By_Ht - 1) * 6 + 1, 6)), "") & Str_Honderd
End If
If By_Tt = 0 Then
If Trim(str_A) <> "" Then
If By_Eh > 0 Then
str_A = str_A & Trim(Str_En)
End If
End If
End If
If By_Tt = 1 Then
If By_Eh < 3 Then
If By_Eh > 1 Then
str_A = str_A & IIf(By_Ht > 0, Trim(Str_EnTrema), "") & Trim(Mid$(Str_Tiental, By_Eh * 9 + 1, 9))
Else
str_A = str_A & IIf(By_Ht > 0, Trim(Str_En), "") & Trim(Mid$(Str_Tiental, By_Eh * 9 + 1, 9))
End If
Else
str_A = str_A & Trim(Mid$(Str_Tiental, By_Eh * 9 + 1, 9))
End If
Else
If By_Eh > 0 Then
str_A = str_A & Trim(Mid$(Str_Eenheid, (By_Eh - 1) * 6 + 1, 6))
Else
str_A = str_A & ""
End If
'str_A = str_A & IIf(By_Eh > 0, Trim(Mid$(Str_Eenheid, (By_Eh - 1) * 6 + 1, 6)), "")
If By_Tt > 1 Then
Select Case By_Eh
Case 2, 3
str_A = str_A & IIf(By_Eh > 0, "ën", "") & Trim(Mid$(Str_Twin_Negentig, (By_Tt - 2) * 9 + 1, 9))
Case Else
str_A = str_A & IIf(By_Eh > 0, "en", "") & Trim(Mid$(Str_Twin_Negentig, (By_Tt - 2) * 9 + 1, 9))
End Select
End If
End If
GroepInLetters = str_A
End Function
Function testgetal()
Dim MyNumber As Double
Dim MyResult As String
MyNumber = 12418343.43
MyResult = GetalInLetters(MyNumber)
MsgBox MyResult
End Function