Adding textfields

From TOF

suppose you have 5 text fields - 4 with data and 1 to hold the total
this code will take those text fields and add them up

Var locale As Locale = Locale.Current

Dim c1,c2, c3, c4, c5 As Currency

c1 = Currency.FromString(TextField1.Text,locale)
c2 = Currency.FromString(TextField2.Text,locale)
c3 = Currency.FromString(TextField3.Text,locale)
c4 = Currency.FromString(TextField4.Text,locale)

c5 = c1 + c2 + c3 + c4

TextField5.Text = c5.ToString(locale)

Note - the LOCALE is NOT optional as Xojo’s docs state
see http://feedback.xojo.com/case/63199

1 Like

From Alberto:

The Locale is optional if the string has only numbers and decimal point (“1123.45”), the locale is required if the number has local formatting (“$1,123.45”,“1.123,45€”).

It’ not just “required”
A Xojo app crashes without one :slight_smile:
Thats really not helpful
feedback://showreport?report_id=63199

Sub Open()
  Var locale As Locale = Locale.Current
  
  Dim c1,c2, c3, c4, c5 As Currency
  
  Try
    c1 = Currency.FromString("123.45")
    c2 = Currency.FromString("$123.45")
    c3 = Currency.FromString("$123.45",locale)
  Catch e As runtimeexception
    Break
    
  End Try
End Sub