Not the farm problem but mine Solved
Posted
#1
(In Topic #684)
Enthusiast

I am looking for code to convert a number to text for a check writing program
I have found excell macros and vb code … there must be gambas code to do it also
Posted
Guru

<IMG src="https://www.cogier.com/gambas/Gambas_Farm.png">
</IMG>
Posted
Enthusiast

Gambas - Gambas Almost Means Basic
does not get me there ?
Posted
Guru

Posted
Enthusiast

but there does not seem to be anything there that will help with my problem
Posted
Guru

Posted
Guru

Or post the problem here…
Posted
Guru

I am looking for code to convert a number to text for a check writing program
Run this code in a 'Graphical application'. It will display text up to 999.99. Hopefully it will get you started.
Code (gambas)
- ' Gambas class file
- $Int = " pounds"
- $Frac = " pence"
- $Int = " dollars"
- $Frac = " cents"
- Me.Center
- BuildForm
- ValueBoxInput.SetFocus
- SText = GetText(iInt) ' Get the Pounds (Dollars)
- sText = GetText(iFrac) ' Get the Pence (Cents)
- Dim sNumbers As String[][] = [["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen"], ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]]
- .Height = 100
- .Width = 500
- .Padding = 5
- .Arrangement = Arrange.Vertical
- .Center
- .H = 28
- .W = 100
- .H = 28
- .W = 160
- .H = 28
- .W = 100
- .H = 28
- .W = 100
- .H = 28
- .W = 100
Posted
Enthusiast

Run this code in a 'Graphical application'. It will display text up to 999.99. Hopefully it will get you started.
thank you I was Halfway there … but you have improved it greatly … that is exactly what I was looking for
thanks again
Marv
Posted
Enthusiast

I world be intrested in any comments or improvements
Thanks for the help.
Marv
Code (gambas)
- Dim sNumbers As String[][] = [["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen"], ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]]
- sResult &= " thousand "
- iLen = 3
- iLen = 3
- iLen = 2
Posted
Guru

I have added a little code to rectify this at line 6. I also change 0 Cents to 'only'. This may be a cultural thing, but that's how we do it this side of the pond, not that I have written a cheque in years. It's all done by BACS now!
Code (gambas)
- Dim sNumbers As String[][] = [["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen"], ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]]
- sResult &= " thousand "
- iLen = 3
- iLen = 3
- iLen = 2
Posted
Enthusiast

I used a test value of 89726.23, and it came back with 22 Cents.
I had that happen one time in my testing also and could not get to happen again … I also added the + .01 for a while then removed it, thinking it was a Quirk
But I did it inside the brackets
Not being a math expert …I don't know which way would be best … ( that is why the books say DO NOT USE FLOAT FOR FINANCE )
I think I will change the input to use a string to prevent that.
I also use electronic payment system for most things …. this software is more of a learning experience for me to learn Gambas
Thank You for the feedback
Marv
Posted
Guru

Not being a math expert …I don't know which way would be best … ( that is why the books say DO NOT USE FLOAT FOR FINANCE )
I think I will change the input to use a string to prevent that.![]()
I think you are correct. Maybe you should take your iValue and multiply it by 100 before you start so that everything is an integer?
Posted
Enthusiast

Later I found i could do the same thing with :
Now I came across the command ENUM:
Code (gambas)
- Enum $ones, $teens, $over19
Which does the same thing if I use it in the Declarations in the beginning of the program, But will not work if I try to put it in the sub, I get a Syntax error …
Any help from anyone ?
k7:k7.1:start [GAMBAS BOOK 3.19.5]
Posted
Enthusiast

<COLOR color="#BF0000">{ PUBLIC | PRIVATE } ENUM Identifier [ = Value ] [ , Identifier [ = Value ] … ]</COLOR>
This keyword declares an enumeration, i.e. a list of integer constants.
If the Value of a constant is not specified, then it will be the value of the previous constant plus one, or zero for the first constant.
All constants are accessible everywhere in the class they are declared.
If the PUBLIC keyword is specified, they are also accessible to the other classes having a reference to an object of this class.
[Gambas-Wiki]
1 guest and 0 members have just viewed this.



