add from txteuro to txttoteuro about sp1

fifiddu70

Well-Known Member
Licensed User
Longtime User
I would like to create an application that allows me to enter through sp1 sum in euros, this appears to be txteuro.text, I would like to add that whenever I select a sum of sp1 and display of txttoteuro.text
I wrote this code but it gives me error.
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim sp1 As Spinner
   Dim txteuro As EditText
   Dim txttoteuro As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout ("calculator")
   sp1.Add(" € 1,00")
   sp1.Add(" € 2,00")
   sp1.Add(" € 3,00")
   sp1.Add(" € 4,00")
   sp1.Add(" € 5,00")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub sp1_ItemClick (Position As Int, Value As Object)
   txteuro.Text = sp1.SelectedItem
   txttoteuro.Text = txttoteuro.Text + txteuro.Text
   
End Sub
 

fifiddu70

Well-Known Member
Licensed User
Longtime User
the image of my example
 

Attachments

  • 2.png
    2.png
    25.6 KB · Views: 282
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is that the values in the Spinner aren't numbers !
€1,00 is not a number so you can't add it to another number.
You could use a code like below using a List to hold the numbers :
B4X:
Sub Process_Globals
    Dim Val, TotalVal As Double
End Sub

Sub Globals
    Dim sp1 As Spinner
    Dim lst1 As List
    Dim txteuro As EditText
    Dim txttoteuro As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout ("calculator")
    sp1.Add(" € 1,00")
    sp1.Add(" € 2,00")
    sp1.Add(" € 3,00")
    sp1.Add(" € 4,00")
    sp1.Add(" € 5,00")
    
    lst1.Initialize
    lst1.Add(1)
    lst1.Add(2)
    lst1.Add(3)
    lst1.Add(4)
    lst1.Add(5)
End Sub

Sub sp1_ItemClick (Position As Int, Value As Object)
    Val = lst1.Get(Position)
    txteuro.Text = Val
    TotalVal = TotalVal + Val
    txttoteuro.Text = TotalVal
End Sub
The test program is attached.

Best regards.
 

Attachments

  • Euro.zip
    6.2 KB · Views: 228
Upvote 0
Top