Function GetalNaarTekst(ByVal MyNumber)
'********************************
'********* Main Function ********
'********************************
Dim Dollars As String, Cents As String, Temp
Dim DecimalPlace As Integer, Count As Integer, i As Integer
Dim tmp() As String
ReDim Place(9) As String
Place(2) = " duizend "
Place(3) = " miljoen "
Place(4) = " miljard "
Place(5) = "onzin getal "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = ""
Case "One"
Dollars = "één Euro"
Case Else
Dollars = Dollars & " Euro"
End Select
Select Case Cents
Case ""
If Dollars <> "" Then Cents = " en "
Cents = Cents & "nul cent"
Case "One"
If Dollars <> "" Then Cents = " en "
Cents = Cents & "één cent"
Case Else
If Dollars <> "" Then
Cents = " en " & Cents & " cent"
Else
Cents = Cents & " cent"
End If
End Select
GetalNaarTekst = Trim(Dollars & Cents)
If InStr(1, GetalNaarTekst, " ") > 0 Then
tmp = Split(GetalNaarTekst, " ")
tmp(LBound(tmp)) = StrConv(tmp(LBound(tmp)), vbProperCase)
GetalNaarTekst = ""
For i = LBound(tmp) To UBound(tmp)
If i > LBound(tmp) Then tmp(i) = LCase(tmp(i))
GetalNaarTekst = GetalNaarTekst & " " & tmp(i)
Next i
End If
GetalNaarTekst = Trim(GetalNaarTekst)
End Function
Function GetHundreds(ByVal MyNumber)
'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
If Mid(MyNumber, 1, 1) = "1" Then
'' Result = GetDigit(Mid(MyNumber, 1, 1)) & "Honderd "
Result = "Honderd "
Else
Result = StrConv(GetDigit(Mid(MyNumber, 1, 1)), vbProperCase) & "honderd "
End If
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Trim(Result) & Trim(LCase(GetTens(Mid(MyNumber, 2))))
Else
Result = Trim(Result) & Trim(LCase(GetDigit(Mid(MyNumber, 3))))
End If
GetHundreds = Result
End Function
Function GetTens(TensText)
'*********************************************
' Converts a number from 10 to 99 into text. *
'*********************************************
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 0 Then ' If value between 0-9...
Result = GetDigit(Right(TensText, 1))
ElseIf Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Tien"
Case 11: Result = "Elf"
Case 12: Result = "Twaalf"
Case 13: Result = "Dertien"
Case 14: Result = "Veertien"
Case 15: Result = "Vijftien"
Case 16: Result = "Zestien"
Case 17: Result = "Zeventien"
Case 18: Result = "Achtien"
Case 19: Result = "Negentien"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "twintig "
Case 3: Result = "dertig "
Case 4: Result = "veertig "
Case 5: Result = "vijftig "
Case 6: Result = "zestig "
Case 7: Result = "zeventig "
Case 8: Result = "tachtig "
Case 9: Result = "negentig "
Case Else
End Select
If Right(TensText, 1) <> 0 Then
Result = GetDigit(Right(TensText, 1)) & "en" & Result
End If
End If
GetTens = Result
End Function
Function GetDigit(Digit)
'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Select Case Val(Digit)
Case 1: GetDigit = "Een"
Case 2: GetDigit = "Twee"
Case 3: GetDigit = "Drie"
Case 4: GetDigit = "Vier"
Case 5: GetDigit = "Vijf"
Case 6: GetDigit = "Zes"
Case 7: GetDigit = "Zeven"
Case 8: GetDigit = "Acht"
Case 9: GetDigit = "Negen"
Case Else: GetDigit = ""
End Select
End Function