Not the farm problem but mine Solved

Post your Gambas programming questions here.
User avatar
grayghost4
Posts: 119
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Not the farm problem but mine Solved

Post by grayghost4 » Monday 07th June 2021 3:04pm

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
Last edited by grayghost4 on Friday 11th June 2021 6:07pm, edited 1 time in total.

User avatar
cogier
Site Admin
Posts: 757
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: the farm is still down ??

Post by cogier » Monday 07th June 2021 3:21pm

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

Image

User avatar
grayghost4
Posts: 119
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Re: the farm is still down ??

Post by grayghost4 » Monday 07th June 2021 3:58pm

must be a dunce but I can't find the page you showed:

http://gambas.sourceforge.net

does not get me there ?

User avatar
cogier
Site Admin
Posts: 757
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: the farm is still down ??

Post by cogier » Monday 07th June 2021 4:59pm

The page shown is what you see when you first open Gambas.

User avatar
grayghost4
Posts: 119
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Re: the farm is still down ??

Post by grayghost4 » Monday 07th June 2021 6:14pm

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 :(

User avatar
BruceSteers
Posts: 654
Joined: Thursday 23rd July 2020 5:20pm

Re: the farm is still down ??

Post by BruceSteers » Monday 07th June 2021 8:15pm

Theres also a menu item in the gambas ide takes you to farm
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 654
Joined: Thursday 23rd July 2020 5:20pm

Re: the farm is still down ??

Post by BruceSteers » Monday 07th June 2021 8:17pm

If there is no solution available, make one 😉

Or post the problem here...
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
cogier
Site Admin
Posts: 757
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: the farm is still down ??

Post by cogier » Tuesday 08th June 2021 11:59am

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.
' Gambas class file

$Int As String
$Frac As String
HBox1 As HBox
HBox2 As HBox
Panel1 As Panel
ValueBoxInput As ValueBox
TextBoxAnswer As TextBox

Public Sub Form_Open()

  If System.Language = "en_GB.UTF-8" Then
    $Int = " pounds"
    $Frac = " pence"
  Endif

  If System.Language = "en_US.UTF-8" Then
    $Int = " dollars"
    $Frac = " cents"
  Endif

  Me.Center
  BuildForm
  ValueBoxInput.SetFocus

End Sub

Public Sub ValueBoxInput_Change()

  Dim iInt As Integer = Fix(ValueBoxInput.Value)
  Dim iFrac As Integer = Int(Frac(ValueBoxInput.Value) * 100)
  Dim sText As String

  SText = GetText(iInt)                                             ' Get the Pounds (Dollars)
  TextBoxAnswer.Text = UCase(sText[0]) & Mid(sText, 2) & $Int
  sText = GetText(iFrac)                                            ' Get the Pence (Cents)
  If Trim(sText) <> "" Then TextBoxAnswer.Text &= " and " & sText & $Frac

  If ValueBoxInput.Value = 0 Then TextBoxAnswer.Clear

End

Public Sub GetText(iValue As Integer) As String

  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"]]

  Dim sValue As String = Str(iValue)
  Dim iLen As Integer = Len(sValue)

  If iLen = 1 Then Return sNumbers[0][Val(sValue)]

  If iLen = 2 And iValue < 20 Then Return sNumbers[1][Val(sValue[1])]
  If iLen = 2 And iValue > 19 Then Return sNumbers[2][Val(sValue[0])] & " " & sNumbers[0][Val(sValue[1])]

  If iLen = 3 And Val(Mid(sValue, 2)) < 10 Then Return sNumbers[0][Val(sValue[0])] & " hundred and " & sNumbers[0][Val(sValue[2])]
  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])]
  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])]

End

Public Sub BuildForm()

  With Me
    .Height = 100
    .Width = 500
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Center
  End With

  With HBox1 = New HBox(Me)
    .H = 28
    .W = 100
  End With

  With ValueBoxInput = New ValueBox(HBox1) As "ValueBoxInput"
    .H = 28
    .W = 160
    .Type = ValueBox.Currency
  End With

  With Panel1 = New Panel(Me)
    .H = 28
    .W = 100
  End With

  With HBox2 = New HBox(Me)
    .H = 28
    .W = 100
  End With

  With TextBoxAnswer = New TextBox(HBox2) As "TextBoxAnswer"
    .H = 28
    .W = 100
    .Expand = True
  End With

End

User avatar
grayghost4
Posts: 119
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Re: the farm is still down ??

Post by grayghost4 » Tuesday 08th June 2021 6:14pm

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

User avatar
grayghost4
Posts: 119
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Re: Not the farm problem but mine Solved

Post by grayghost4 » Friday 11th June 2021 10:48pm

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
Public Sub GetText(iValue As Float) As String
 
  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"]]

  Dim sValue As String = Str(Fix(iValue))
  Dim icents As Integer = Int(Frac(iValue) * 100)
  Dim iLen As Integer = Len(sValue)
  Dim sResult As String
  
  Dim $ones As Integer = 0
  Dim $teens As Integer = 1
  Dim $over19 As Integer = 2 

  If iLen = 5 Then 
    If Val(Mid(sValue, 1, 2)) < 20 Then sResult = sNumbers[$teens][Val(Mid(sValue, 2, 1))] 
    If Val(Mid(sValue, 1, 2)) > 19 Then sResult = sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
    sResult &= " thousand " 
    svalue = Right(svalue, 3)
    iLen = 3    
  Endif 
  
  If iLen = 4 Then
     sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " thousand " 
     svalue = Right(svalue, 3)
     iLen = 3
  Endif 
  
  If iLen = 3 And Val(Left(sValue, 1)) Then 
      sResult &= sNumbers[$ones][Val(Left(sValue, 1))] & " hundred " 
      svalue = Right(svalue, 2)
      iLen = 2
   Endif 
   
 If iLen = 2 Then 
   If Val(Right(sValue, 2)) < 20 Then sResult &= sNumbers[$teens][Val(Mid(sValue, 2, 1))]
   If Val(Right(svalue, 2)) > 19 Then sResult  &= sNumbers[$over19][Val(Mid(sValue, 1, 1))] & " " & sNumbers[$ones][Val(Mid(sValue, 2, 1))]
 Endif 
  If iLen = 1 Then sResult &= sNumbers[$ones][Val(sValue)]
  
  Return  = "* * * " & UCase(sResult[0]) & Mid(sResult, 2) & " dollars and " & icents & " cents" & " * * *" 
  
End

Post Reply