|
-
Jan 28th, 2003, 10:35 PM
#1
Thread Starter
Addicted Member
Anybody have?
Anybody have a currency conversion program they care to donate..I don't think this one will work for me!! I appreciate your help!!!
Function NumToWord (numval)
Dim NTW, NText, dollars, cents, NWord, totalcents As String
Dim decplace, TotalSets, cnt, LDollHold As Integer
ReDim NumParts(9) As String'Array for Amount (sets of three)
ReDim Place(9) As String 'Array containing place holders
Dim LDoll As Integer 'Length of the Dollars Text Amount
Place(2) = " Thousand "'
Place(3) = " Million "'Place holder names for money
Place(4) = " Billion "'amounts
Place(5) = " Trillion "'
NTW = "" 'Temp value for the function
NText = round_curr(numval)'Roundup the cents to eliminate
cents gr 2
NText = Trim(Str(NText)) 'String representation of amount
decplace = InStr(Trim(NText), ".")'Position of decimal 0 if none
dollars = Trim(Left(NText, IIf(decplace = 0, Len(numval),
decplace
- 1)))
LDoll = Len(dollars)
cents = Trim(Right(NText, IIf(decplace = 0, 0, Abs(decplace -
Len(NText)))))
If Len(cents) = 1 Then
cents = cents & "0"
End If
If (LDoll Mod 3) = 0 Then
TotalSets = (LDoll \ 3)
Else
TotalSets = (LDoll \ 3) + 1
End If
cnt = 1
LDollHold = LDoll
Do While LDoll > 0
NumParts(cnt) = IIf(LDoll > 3, Right(dollars, 3),
Trim(dollars))
dollars = IIf(LDoll > 3, Left(dollars, (IIf(LDoll < 3, 3,
LDoll)) - 3), "")
LDoll = Len(dollars)
cnt = cnt + 1
Loop
For cnt = TotalSets To 1 Step -1 'step through NumParts
array
NWord = GetWord(NumParts(cnt))'convert 1 element of
NumParts
NTW = NTW & NWord 'concatenate it to temp
variable
If NWord <> "" Then NTW = NTW & Place(cnt)
Next cnt 'loop through
If LDollHold > 0 Then
NTW = NTW & " DOLLARS and "'concatenate text
Else
NTW = NTW & " NO DOLLARS and "'concatenate text
End If
totalcents = GetTens(cents) 'Convert cents part to word
If totalcents = "" Then totalcents = "NO" 'Concat NO if cents=0
NTW = NTW & totalcents & " CENTS"'Concat Dollars and Cents
NumToWord = NTW 'Assign word value to
function
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|