This is my first project developed with Basic4Android
Its a very straight-forward tips calcuator
Its a very straight-forward tips calcuator
B4X:
'Tips Calculator - Jim Brown
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim EditBill As EditText
Dim SpinnerTip As Spinner
Dim SpinnerNumPeople As Spinner
Dim LabelBillTotal As Label
Dim LabelEachPays As Label
Dim billamount As Double
Dim percent As Double
Dim numpeople As Double
Dim billtotal As Double
Dim perperson As Double
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("TipsCalcLayout")
SpinnerTip.AddAll(Array As String("0","5","10","15","20","25","30"))
SpinnerTip.SelectedIndex=2
For n=1 To 25 : SpinnerNumPeople.Add(n) : Next
SpinnerNumPeople.SelectedIndex=1
EditBill.Text="100.0"
End Sub
Sub SpinnerTip_ItemClick (Position As Int, Value As Object)
percent=Value
Calculate
End Sub
Sub SpinnerNumPeople_ItemClick (Position As Int, Value As Object)
numpeople=Value
Calculate
End Sub
Sub ButtonCalculate_Click
Calculate
End Sub
Sub Calculate
' need to check if edit box contents are valid
If Not(IsNumber(EditBill.Text)) Then
EditBill.Text="0.0"
End If
billamount=Abs(EditBill.Text)
billtotal=billamount+((billamount*percent)/100.0)
perperson=billtotal/numpeople
LabelBillTotal.Text=Round2(billtotal,2)
LabelEachPays.Text=Round2(perperson,2)
End Sub