Android Question How to deal with EditText during calculations

Alberto Michelis

Well-Known Member
Licensed User
I have many EditText which are numbers and I deal with it all the time no knowing what todo having many error of double"" and so on, no I got an unexpected Array, see image please and I just dont know how to program a simple caculation.

A routine like:

Sub CalcTot
   If eDias.Text>0 And eTasa.Text>0 Then
     Dim d As Int
     dVto.Text = DateTime.Date(DateTime.Add(DateTime.Now,0,0,d))
     eIntereses.Text = (ePrecio.Text * eCantidad.Text) * (eTasa.Text/100) * d /365
     eIntereses.Text = NumberFormat2(eIntereses.Text,0,2,2,True)
   End If
   dTotal.Text = (ePrecio.Text * eCantidad.Text) + eIntereses.Text
   dTotal.Text = NumberFormat2(dTotal.Text,0,2,2,True)
can give an infinite number of errors if one of the components is "" or null or...

How must I code this?



Licensed User
Some suggestions.

1) do not use views for calculations.
It is better to use variables, ALSO to keep separate GUI from the code;
So you should have:
Dim Dias As Int
Dias = eDias.Text

2) Verify the user input (in eDias, for example) and set the EditText.InputType

3) if you really want to test this way:
If eDias.Text > 0
you can use:
If "0" & eDias.Text > 0
given that a zero on the left does not change the numeric value.

Alberto Michelis

Well-Known Member
Licensed User
Thanks Lucas, the idea of use
Dim Dias As Int
Dias = eDias.Text
that means a Dim and an assignment for each edittext in each activity... does it have any impact on perfomance?