Zahlwort
25.09.2004 21:34:12
Matthias
Leider konnte mir noch keiner weiterhelfen.
1. Problem:Ich möchte untenstehende Funktion aufrufen, wenn ich meine UF mittels Commanbutton verlasse.
2. Problem: Ich verlasse Textfeld1 in der UF mittels TabTaste. Dadurch soll im Textfeld3(mittels unten stehender Funktion als Zahlwort) die Zahl aus Textfeld2(hier numerisch) erscheinen.
Die Zahl in Textfeld2 resultiert aus einem Eintrag in Textfeld1.
Kann jemand helfen?
Dim BisNeunzehn As Variant
Dim Zehner As Variant
Dim Tausender As Variant
Function ZWort(dZahl As Double, Optional bln As Boolean)
Dim dRest As Double
dRest = WorksheetFunction.Round((dZahl - Fix(dZahl)), 2) * 100
dZahl = Fix(dZahl)
BisNeunzehn = Array("", "ein", "zwei", "drei", "vier", _
"fünf", "sechs", "sieben", "acht", "neun", "zehn", _
"elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", _
"sechzehn", "siebzehn", "achtzehn", "neunzehn")
Zehner = Array("", "zehn", "zwanzig", "dreißig", _
"vierzig", "fünfzig", "sechzig", "siebzig", _
"achtzig", "neunzig")
Tausender = Array("", "tausend", "millionen", "milliarden")
If dRest = 0 Then
ZWort = Text(dZahl)
Else
If bln Then
ZWort = Text(dZahl) And " " And dRest And "/00"
Else
ZWort = Text(dZahl)
End If
End If
End Function
Private Function Wort(wert As Integer) As String
Dim h As Integer
h = wert Mod 100
If h < 20 Then
Wort = BisNeunzehn(h)
Else
Wort = BisNeunzehn(h Mod 10) & IIf(h Mod 10 > 0, "und", "") & _
Zehner(Int(h / 10))
End If
h = (wert Mod 1000 - h) / 100
If h > 0 Then Wort = BisNeunzehn(h) & "hundert" & Wort
End Function
Private Function Text(wert As Double)
Dim l As Integer, i As Integer, p As Integer
If InStr(1, Str(wert), " , ") = 0 And InStr(1, Str(wert), " . ") = 0 Then
For i = 1 To 1 + Int(Len(Str(wert)) / 3)
p = Val("0" & Mid("000" + Str(wert), _
Len("000" & Str(wert)) - i * 3 + 1, 3))
If p > 0 Then Text = Wort(p) & Tausender(i - 1) & Text
Next
Else
Text = "#Ganzzahl!"
End If
If Right(Text, 3) = "ein" Then Text = Text & "s"
End Function