I am starting to feel silly.
I have an activity that updates the database. When I run the activity again, the update does not show. But when I look at the content of the updated table (through other activities), the update was performed.
(detail. the field OneRM is altered, but when I rerun this activity is shows the old value, while other activities show the new value.)
The code is now a bit messy, because of different experiments.
I really could use some help here
I have an activity that updates the database. When I run the activity again, the update does not show. But when I look at the content of the updated table (through other activities), the update was performed.
(detail. the field OneRM is altered, but when I rerun this activity is shows the old value, while other activities show the new value.)
The code is now a bit messy, because of different experiments.
I really could use some help here
B4X:
'Activity module new 1 rm test
Sub Process_Globals
Dim sql1 As SQL
End Sub
Sub Globals
'from the design
Dim btnCancel As Button
Dim btnSaveAndExit As Button
Dim edtDate As EditText
Dim edtLoad As EditText
Dim edtReps As EditText
Dim ExerciseLabel As Label
Dim ImageView1 As ImageView
Dim lblLoad As Label
Dim lblRep As Label
Dim lblSet As Label
Dim tglProper As ToggleButton
Dim lblProper As Label
Dim lblOneRM As Label
Dim edtOneRM As EditText
Dim spnExercise As Spinner
Dim SelectedExercise As String : SelectedExercise = ""
Dim OneRMCalc As Float
Dim CurrentOneRM As Int
Dim CurrentProper As Int
Dim Today As Long
Dim dte As String
Dim ExerciseArray(100) As String
Dim NewOneRM As Int : NewOneRM = 0
Dim NewProper As Int : NewProper = 0
End Sub
Sub Activity_Create(FirstTime As Boolean)
sql1.Initialize(File.DirDefaultExternal, "fit.db", True)
Activity.LoadLayout("OneRMTest")
edtOneRM.Text = 0
GetDate
edtDate.Text = dte
edtLoad.Text=0
edtReps.Text=0
edtLoad.TextColor = Colors.Red
edtReps.TextColor = Colors.Red
'Load exercises in spinner
spnExercise.Clear
PopulateSpinner
spnExercise.Enabled= True
spnExercise.Prompt = "Select Exercise"
spnExercise.TextSize = 12dip
spnExercise.AddAll(ExerciseArray)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub PopulateSpinner
Dim exCurs1 As Cursor
exCurs1 = sql1.ExecQuery("Select exercise from Exercises order by exercise")
For i = 0 To exCurs1.RowCount -1
exCurs1.position = i
ExerciseArray(i) = exCurs1.GetString("exercise")
Next
exCurs1.Close
End Sub
Sub GetDate
Today = DateTime.Now
DateTime.DateFormat = "dd-MMM-yyyy"
dte = DateTime.Date(Today)
'Msgbox(dte,"datum")
End Sub
Sub lblSet_Click
End Sub
Sub lblRep_Click
End Sub
Sub lblLoad_Click
End Sub
Sub ExerciseLabel_Click
End Sub
Sub edtReps_TextChanged (Old As String, New As String)
End Sub
Sub edtReps_FocusChanged (HasFocus As Boolean)
If edtReps.Text = 0 Then
edtReps.TextColor = Colors.red
Else
edtReps.TextColor = Colors.Blue
OneRMCalc = edtLoad.text*(36 / (37 - edtReps.text))'based on the Brzycki formula
End If
If edtReps.Text > 5 AND edtReps.Text< 13 Then 'Proper number of reps
CurrentProper = 0
tglProper.checked = True
edtOneRM.TextColor = Colors.Green
Else
tglProper.checked = False
edtOneRM.TextColor = Colors.Red
End If
End Sub
Sub edtLoad_TextChanged (Old As String, New As String)
End Sub
Sub edtLoad_FocusChanged (HasFocus As Boolean)
If edtLoad.Text = 0 Then
edtLoad.TextColor = Colors.red
Else
edtLoad.TextColor = Colors.Blue
If edtReps.text <> 0 Then
OneRMCalc = edtLoad.text*(36 / (37 - edtReps.text))'based on the Brzycki formula
End If
End If
edtOneRM.Text = OneRMCalc
If edtReps.Text > 5 AND edtReps.Text< 13 Then 'Proper number of reps
CurrentProper = 0
tglProper.checked = True
edtOneRM.TextColor = Colors.Green
Else
tglProper.checked = False
edtOneRM.TextColor = Colors.Red
End If
End Sub
Sub edtDate_TextChanged (Old As String, New As String)
End Sub
Sub edtDate_FocusChanged (HasFocus As Boolean)
End Sub
Sub btnSaveAndExit_Click
NewOneRM = edtOneRM.Text
If tglProper.Checked Then
NewProper = 1
Else
NewProper = 0
End If
Msgbox (SelectedExercise&" "& NewOneRM&" "& NewProper,"Current")
If SelectedExercise = "" OR NewOneRM = 0 Then
Msgbox ("No value to save", "Error")
Activity.Finish
Else
'Msgbox ("doing the safe thing","here")
Dim WhereFields As Map
WhereFields.Initialize
WhereFields.Put("exercise", SelectedExercise)
DBUtils.UpdateRecord(sql1, "Exercises", "OneRM", NewOneRM, WhereFields)
DBUtils.UpdateRecord(sql1, "Exercises", "OneRMProper", NewProper, WhereFields)
End If
Activity.Finish
End Sub
Sub btnCancel_Click
Activity.Finish
End Sub
Sub spnExercise_ItemClick (Position As Int, Value As Object)
Dim excurs2 As Cursor
excurs2 = sql1.ExecQuery("Select id, exercise, OneRm, OneRMProper from Exercises")
excurs2.Position = Position
CurrentOneRM = excurs2.Getint("OneRM")
CurrentProper = excurs2.Getint("OneRMProper")
edtOneRM.Text = CurrentOneRM
If CurrentProper = 0 Then
tglProper.checked = False
Else
tglProper.checked = True
End If
SelectedExercise = Value
excurs2.Close
'Msgbox(Position&": "&Value,"selected value")
End Sub
Sub tglProper_CheckedChange(Checked As Boolean)
End Sub
Sub lblProper_Click
Msgbox("A proper 1RM test has between 6 and 12 repetitions in one minute","Proper 1 RM test")
End Sub
Sub lblOneRM_Click
End Sub