i have been trying to get this code to work but keep getting errors. what am I doing wrong? the errors that I am getting are:
'Public Property Left() As Integer' has no parameters and its return type cannot be indexed.
'Public ReadOnly Property Right() As Integer' has no parameters and its return type cannot be indexed. -
Public Function ConvertCurrencyToEnglish(ByVal MyNumber As Double) As String
-
Dim Temp As String
-
Dim Dollars, Cents As String
-
Dim DecimalPlace, Count As Integer
-
Dim Place(9) As String
-
Dim Numb As String
-
-
Place(2) = " Thousand ": Place(3) = " Million ": Place(4) = "Billion"
-
-
: Place(5) = " Trillion "
-
-
' Convert Numb to a string, trimming extra spaces.
-
Numb = Trim(Str(MyNumber))
-
' Find decimal place.
-
DecimalPlace = InStr(Numb, ".")
-
' If we find decimal place...
-
If DecimalPlace > 0 Then
-
' Convert cents
-
Temp = Left(Mid(Numb, DecimalPlace + 1) & "00", 2)
-
Cents = ConvertTens(Temp)
-
' Strip off cents from remainder to convert.
-
Numb = Trim(Left(Numb, DecimalPlace - 1))
-
End If
-
Count = 1
-
Do While Numb <> ""
-
' Convert last 3 digits of Numb to English dollars.
-
Temp = ConvertHundreds(Right(Numb, 3))
-
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
-
If Len(Numb) > 3 Then
-
' Remove last 3 converted digits from Numb.
-
Numb = Left(Numb, Len(Numb) - 3)
-
Else
-
Numb = ""
-
End If
-
Count = Count + 1
-
Loop
-
-
' Clean up dollars.
-
Select Case Dollars
-
Case "": Dollars = "No Dollars"
-
Case "One": Dollars = "One Dollar"
-
Case Else: Dollars = Dollars & " Dollars"
-
End Select
-
-
' Clean up cents.
-
Select Case Cents
-
Case "": Cents = " And No Cents"
-
Case "One": Cents = " And One Cent"
-
Case Else: Cents = " And " & Cents & " Cents"
-
End Select
-
-
ConvertCurrencyToEnglish = Dollars & Cents
-
-
End Function
-
-
Private Function ConvertHundreds(ByVal MyNumber As String) As String
-
Dim Result As String
-
-
' Exit if there is nothing to convert.
-
If Val(MyNumber) = 0 Then Exit Function
-
-
' Append leading zeros to number.
-
MyNumber = Right("000" & MyNumber, 3)
-
' Do we have a hundreds place digit to convert?
-
If Left(MyNumber, 1) <> "0" Then
-
Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
-
End If
-
' Do we have a tens place digit to convert?
-
If Mid(MyNumber, 2, 1) <> "0" Then
-
Result = Result & ConvertTens(Mid(MyNumber, 2))
-
Else
-
' If not, then convert the ones place digit.
-
Result = Result & ConvertDigit(Mid(MyNumber, 3))
-
End If
-
ConvertHundreds = Trim(Result)
-
-
End Function
-
-
Private Function ConvertTens(ByVal MyTens As String) As String
-
Dim Result As String
-
-
' Is value between 10 and 19?
-
If (MyTens, 1)) = 1 Then
-
Select Case Val(MyTens)
-
Case 10: Result = "Ten"
-
Case 11: Result = "Eleven"
-
Case 12: Result = "Twelve"
-
Case 13: Result = "Thirteen"
-
Case 14: Result = "Fourteen"
-
Case 15: Result = "Fifteen"
-
Case 16: Result = "Sixteen"
-
Case 17: Result = "Seventeen"
-
Case 18: Result = "Eighteen"
-
Case 19: Result = "Nineteen"
-
Case Else
-
End Select
-
Else
-
' .. otherwise it's between 20 and 99.
-
Select Case (MyTens, 1)
-
Case 2: Result = "Twenty "
-
Case 3: Result = "Thirty "
-
Case 4: Result = "Forty "
-
Case 5: Result = "Fifty "
-
Case 6: Result = "Sixty "
-
Case 7: Result = "Seventy "
-
Case 8: Result = "Eighty "
-
Case 9: Result = "Ninety "
-
Case Else
-
End Select
-
' Convert ones place digit.
-
Result = Result & ConvertDigit(Right(MyTens, 1))
-
End If
-
ConvertTens = Result
-
-
End Function
-
-
Private Function ConvertDigit(ByVal MyDigit As String) As String
-
-
Select Case Val(MyDigit)
-
Case 1: ConvertDigit = "One"
-
Case 2: ConvertDigit = "Two"
-
Case 3: ConvertDigit = "Three"
-
Case 4: ConvertDigit = "Four"
-
Case 5: ConvertDigit = "Five"
-
Case 6: ConvertDigit = "Six"
-
Case 7: ConvertDigit = "Seven"
-
Case 8: ConvertDigit = "Eight"
-
Case 9: ConvertDigit = "Nine"
-
Case Else: ConvertDigit = ""
-
End Select
-
-
End Function
-
9 2283
You don't say whether this is VB or VBA. I am moving it to the VB forum for the moment.
Also what are you trying to do here - Temp = Left(Mid(Numb, DecimalPlace + 1) & "00", 2)
and here - MyNumber = Right("000" & MyNumber, 3)
This doesn't make any sense.
Also there is a problem with this function -
Private Function ConvertTens(ByVal MyTens As String) As String
-
Dim Result As String
-
-
' Is value between 10 and 19?
-
If (MyTens, 1)) = 1 Then ' what are you trying to do here ???
-
Select Case Val(MyTens)
-
Case 10: Result = "Ten"
-
Case 11: Result = "Eleven"
-
Case 12: Result = "Twelve"
-
Case 13: Result = "Thirteen"
-
Case 14: Result = "Fourteen"
-
Case 15: Result = "Fifteen"
-
Case 16: Result = "Sixteen"
-
Case 17: Result = "Seventeen"
-
Case 18: Result = "Eighteen"
-
Case 19: Result = "Nineteen"
-
Case Else
-
End Select
-
Else
-
' .. otherwise it's between 20 and 99.
-
Select Case (MyTens, 1) ' and here as well ???
-
Case 2: Result = "Twenty "
-
Case 3: Result = "Thirty "
-
Case 4: Result = "Forty "
-
Case 5: Result = "Fifty "
-
Case 6: Result = "Sixty "
-
Case 7: Result = "Seventy "
-
Case 8: Result = "Eighty "
-
Case 9: Result = "Ninety "
-
Case Else
-
End Select
-
' Convert ones place digit.
-
Result = Result & ConvertDigit(Right(MyTens, 1))
-
End If
-
ConvertTens = Result
-
-
End Function
-
I'm sorry I am using vb. net 2005. I am trying to enter the amount in numbers on one form and have it appear converted into words in a textbox or label on the second form like when you write a check. If there are any easier ways please feel free to clarify for me.
I'm sorry I am using vb. net 2005
OK you are in the right forum now. Have a look at the issues I pointed out.
- Private Function ConvertTens(ByVal MyTens As String) As String
-
Dim Result As String
-
-
' Is value between 10 and 19?
-
If (MyTens, 1)) = 1 Then ' what are you trying to do here ???( this is where i'm trying to convert the numbers 10 to 19 into words)
-
Select Case Val(MyTens)
-
Case 10: Result = "Ten"
-
Case 11: Result = "Eleven"
-
Case 12: Result = "Twelve"
-
Case 13: Result = "Thirteen"
-
Case 14: Result = "Fourteen"
-
Case 15: Result = "Fifteen"
-
Case 16: Result = "Sixteen"
-
Case 17: Result = "Seventeen"
-
Case 18: Result = "Eighteen"
-
Case 19: Result = "Nineteen"
-
Case Else
-
End Select
-
Else
-
' .. otherwise it's between 20 and 99.
-
Select Case (MyTens, 1) ' and here as well ???(trying to convert the other numbers)
-
Case 2: Result = "Twenty "
-
Case 3: Result = "Thirty "
-
Case 4: Result = "Forty "
-
Case 5: Result = "Fifty "
-
Case 6: Result = "Sixty "
-
Case 7: Result = "Seventy "
-
Case 8: Result = "Eighty "
-
Case 9: Result = "Ninety "
-
Case Else
-
End Select
-
' Convert ones place digit.
-
Result = Result & ConvertDigit(Right(MyTens, 1))
-
End If
-
ConvertTens = Result
-
-
End Function
Sorry to be more specific
What is this statement?
If (MyTens, 1)) = 1 Then
If (MyTens, 1)) = 1 Then is to covert the tens place of the number
If (MyTens, 1)) = 1 Then is to covert the tens place of the number
Its not doing that. You need to isolate the number as follows: -
Dim myNum As Integer
-
-
myNum = CInt(Right(MyTens, 2)) ' myNum now holds a two digit number
-
If myNum > 9 And myNum < 20 Then
-
-
ok will try that thank you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PoulsenL |
last post by:
I have a number of text fields with different ways of exressing currency.
Examples:
1 512,3 M
0.214,0 m
1 123 k
1,234,567
1.235.458,90
1,234,324 m (Where in this case m is to be conveyed as...
|
by: Caesar Augustus |
last post by:
Hello Tom,
Long time listener, first time caller...
I have been working with vb code to automate a salary increase process
that not only rounds to the nearest penny but also rounds to the...
|
by: Rolan |
last post by:
I would appreciate anyone's assistance to sort out what change in code
is needed for 'TextToDigits()' as shown below. The function does
convert the text to numbers, but it is two decimals off,...
|
by: Penfold |
last post by:
I'd appreciate help converting student average test scores into grades. My
problem is that I need to allocate one of about 20 grades (3a,3b,3c,4a,4b,4c
etc through to 8c plus a couple of others)....
|
by: pebelund |
last post by:
Hi
I got an .aspx that got the following code (example)
<td width="120">
<% = row %>
</td>
row takes a value from a SQL db, that is a string of numbers.
On the webbsite I want this to show...
|
by: chengsi |
last post by:
I have based a report on a crosstab query. This query has eliminated all formats, i.e. all fields including those containing numbers are now stored as text.
Is there a way that i can get Access...
|
by: Dilip |
last post by:
Recently in our code, I ran into a situation where were stuffing a
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused...
|
by: missinglinq |
last post by:
From the Access Object Dialog Box click on "Modules"
Click on new to make a new module
Copy then paste the following code into the new module:
Function SayNo(ByVal N As Currency) As String
...
|
by: =?ISO-8859-1?Q?Marcel_M=FCller?= |
last post by:
clintonb wrote:
There is nothing like an original double amount. If you care about
rounding errors you must not store any currency value in an approximate
number. You must not do this even once....
|
by: Guillermo_Lopez |
last post by:
Hello All,
I am using VBA in access to perform some calculations. There is a
particular sumation that is wrong (barely).
this code is withing a loop.
TDist = TDist + TempDist
Both TDist...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |