Not the farm problem but mine Solved

Post

Posted
Rating:
#1 (In Topic #684)
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 I can not find the gambas farm  

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
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
There was an issue with Gambas.One accessing the Gambas Farm, so we are not doing it any more. You can access the Farm from Gambas: -

<IMG src="https://www.cogier.com/gambas/Gambas_Farm.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
must be a dunce but I can't find the page you showed:

Gambas - Gambas Almost Means Basic

does not get me there ?
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
The page shown is what you see when you first open Gambas.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Like I said I am a DUNCE   , I have been looking on line for a week for it  :o

but there does not seem to be anything there that will help with my problem  :(
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
Theres also a menu item in the gambas ide takes you to farm
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
If there is no solution available,  make one <EMOJI seq="1f609" tseq="1f609">😉</EMOJI>

Or post the problem here…
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Guru
cogier is in the usergroup ‘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)

  1. ' Gambas class file
  2.  
  3. $Int As String
  4. $Frac As String
  5. HBox1 As HBox
  6. HBox2 As HBox
  7. Panel1 As Panel
  8. ValueBoxInput As ValueBox
  9. TextBoxAnswer As TextBox
  10.  
  11. Public Sub Form_Open()
  12.  
  13.   If System.Language = "en_GB.UTF-8" Then
  14.     $Int = " pounds"
  15.     $Frac = " pence"
  16.  
  17.   If System.Language = "en_US.UTF-8" Then
  18.     $Int = " dollars"
  19.     $Frac = " cents"
  20.  
  21.   Me.Center
  22.   BuildForm
  23.   ValueBoxInput.SetFocus
  24.  
  25.  
  26. Public Sub ValueBoxInput_Change()
  27.  
  28.   Dim iInt As Integer = Fix(ValueBoxInput.Value)
  29.   Dim iFrac As Integer = Int(Frac(ValueBoxInput.Value) * 100)
  30.   Dim sText As String
  31.  
  32.   SText = GetText(iInt)                                             ' Get the Pounds (Dollars)
  33.   TextBoxAnswer.Text = UCase(sText[0]) & Mid(sText, 2) & $Int
  34.   sText = GetText(iFrac)                                            ' Get the Pence (Cents)
  35.   If Trim(sText) <> "" Then TextBoxAnswer.Text &= " and " & sText & $Frac
  36.  
  37.   If ValueBoxInput.Value = 0 Then TextBoxAnswer.Clear
  38.  
  39.  
  40. Public Sub GetText(iValue As Integer) As String
  41.  
  42.   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"]]
  43.  
  44.   Dim sValue As String = Str(iValue)
  45.   Dim iLen As Integer = Len(sValue)
  46.  
  47.   If iLen = 1 Then Return sNumbers[0][Val(sValue)]
  48.  
  49.   If iLen = 2 And iValue < 20 Then Return sNumbers[1][Val(sValue[1])]
  50.   If iLen = 2 And iValue > 19 Then Return sNumbers[2][Val(sValue[0])] & " " & sNumbers[0][Val(sValue[1])]
  51.  
  52.   If iLen = 3 And Val(Mid(sValue, 2)) < 10 Then Return sNumbers[0][Val(sValue[0])] & " hundred and " & sNumbers[0][Val(sValue[2])]
  53.   If iLen = 3 And Val(Mid(sValue, 2)) > 9 And Val(Mid(sValue, 2)) < 20 Then Return sNumbers[0][Val(sValue[0])] & " hundred and " & sNumbers[1][Val(sValue[2])]
  54.   If iLen = 3 And Val(Mid(sValue, 2)) > 19 Then Return sNumbers[0][Val(sValue[0])] & " hundred and " & sNumbers[2][Val(sValue[1])] & " " & sNumbers[0][Val(sValue[2])]
  55.  
  56.  
  57. Public Sub BuildForm()
  58.  
  59.   With Me
  60.     .Height = 100
  61.     .Width = 500
  62.     .Padding = 5
  63.     .Arrangement = Arrange.Vertical
  64.     .Center
  65.  
  66.   With HBox1 = New HBox(Me)
  67.     .H = 28
  68.     .W = 100
  69.  
  70.   With ValueBoxInput = New ValueBox(HBox1) As "ValueBoxInput"
  71.     .H = 28
  72.     .W = 160
  73.     .Type = ValueBox.Currency
  74.  
  75.   With Panel1 = New Panel(Me)
  76.     .H = 28
  77.     .W = 100
  78.  
  79.   With HBox2 = New HBox(Me)
  80.     .H = 28
  81.     .W = 100
  82.  
  83.   With TextBoxAnswer = New TextBox(HBox2) As "TextBoxAnswer"
  84.     .H = 28
  85.     .W = 100
  86.     .Expand = True
  87.  
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Enthusiast
GrayGhost is in the usergroup ‘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  :D

thanks again
Marv
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
I went at the project a little differently than you did I wanted a max of 99999.99 all in one function..
I world be intrested in any comments or improvements
Thanks for the help.
Marv

Code (gambas)

  1. Public Sub GetText(iValue As Float) As String
  2.  
  3.   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"]]
  4.  
  5.   Dim sValue As String = Str(Fix(iValue))
  6.   Dim icents As Integer = Int(Frac(iValue) * 100)
  7.   Dim iLen As Integer = Len(sValue)
  8.   Dim sResult As String
  9.  
  10.   Dim $ones As Integer = 0
  11.   Dim $teens As Integer = 1
  12.   Dim $over19 As Integer = 2
  13.  
  14.   If iLen = 5 Then
  15.     If Val(Mid(sValue, 1, 2)) < 20 Then sResult = sNumbers[$teens][Val(Mid(sValue, 2, 1))]
  16.     If Val(Mid(sValue, 1, 2)) > 19 Then sResult = sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
  17.     sResult &= " thousand "
  18.     svalue = Right(svalue, 3)
  19.     iLen = 3    
  20.   Endif
  21.  
  22.   If iLen = 4 Then
  23.      sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " thousand "
  24.      svalue = Right(svalue, 3)
  25.      iLen = 3
  26.   Endif
  27.  
  28.   If iLen = 3 And Val(Left(sValue, 1)) Then
  29.       sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " hundred "
  30.       svalue = Right(svalue, 2)
  31.       iLen = 2
  32.    Endif
  33.    
  34.  If iLen = 2 Then
  35.    If Val(Right(sValue, 2)) < 20 Then sResult &= sNumbers[$teens][Val(Mid(sValue, 2, 1))]
  36.    If Val(Right(svalue, 2)) > 19 Then sResult  &= sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
  37.   If iLen = 1 Then sResult &= sNumbers[$ones][Val(sValue)]
  38.  
  39.   Return  = "* * * " & UCase(sResult[0]) & Mid(sResult, 2) & " dollars and " & icents & " cents" & " * * *"
  40.  
  41.  
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Guru
cogier is in the usergroup ‘Guru’
I used a test value of 89726.23, and it came back with 22 Cents.

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)

  1. Public Sub GetText(iValue As Float) As String
  2.  
  3.   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"]]
  4.  
  5.   Dim sValue As String = Str(Fix(iValue))
  6.   Dim icents As Integer = Int((Frac(iValue) * 100) + 0.01) ''Changed to stop rounding down
  7.   Dim iLen As Integer = Len(sValue)
  8.   Dim sResult, sCents As String ''Added sCents
  9.  
  10.   Dim $ones As Integer = 0
  11.   Dim $teens As Integer = 1
  12.   Dim $over19 As Integer = 2
  13.  
  14.   If iLen = 5 Then
  15.     If Val(Mid(sValue, 1, 2)) < 20 Then sResult = sNumbers[$teens][Val(Mid(sValue, 2, 1))]
  16.     If Val(Mid(sValue, 1, 2)) > 19 Then sResult = sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
  17.     sResult &= " thousand "
  18.     svalue = Right(svalue, 3)
  19.     iLen = 3
  20.  
  21.   If iLen = 4 Then
  22.     sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " thousand "
  23.     svalue = Right(svalue, 3)
  24.     iLen = 3
  25.  
  26.   If iLen = 3 And Val(Left(sValue, 1)) Then
  27.     sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " hundred "
  28.     svalue = Right(svalue, 2)
  29.     iLen = 2
  30.  
  31.   If iLen = 2 Then
  32.     If Val(Right(sValue, 2)) < 20 Then sResult &= sNumbers[$teens][Val(Mid(sValue, 2, 1))]
  33.     If Val(Right(svalue, 2)) > 19 Then sResult &= sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
  34.   If iLen = 1 Then sResult &= sNumbers[$ones][Val(sValue)]
  35.  
  36.   If iCents = 0 Then sCents = "only" Else sCents = "and " & Str(iCents) & " cents" ''Added
  37.  
  38.   Return "* * * " & UCase(sResult[0]) & Mid(sResult, 2) & " dollars " & sCents & " * * *" ''Changed
  39.  
  40.  
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Enthusiast
GrayGhost is in the usergroup ‘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    

Code (gambas)

  1.  Dim icent As Integer = Int(Frac(iValue) * 100.01)

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.   :D

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
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Guru
cogier is in the usergroup ‘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. :D

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?
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
In my program above I used a DIM statement :

Code (gambas)

  1.   Dim $ones As Integer = 0
  2.   Dim $teens As Integer = 1
  3.   Dim $over19 As Integer = 2
  4.  

Later I found i could do the same thing with :

Code (gambas)

  1. Dim $ones As Integer = 0, $teens As Integer = 1, $over19 As Integer = 2

Now I came across the command ENUM:

Code (gambas)

  1. 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]
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
Enumeration declaration

<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]
Online now: No Back to the top
1 guest and 0 members have just viewed this.