Hi Alberto, Kem,
Kem. That is the document I looked at, which I tried but couldn’t seem to get to work…
Emile: I have a textbox that is filled with a dateTime…
app.startIncidentTime = new date
app.startIncidentTime = DateTime.Now
mainWindow.startTextfield.text = str(app.startIncidentTime)
Version of Xojo is: 2020 Release 2.1
I have NOT been able to get the xojo.core.data to work… so… there isn’t anything in the code right now. I’ve rolled it back to the last working version as I mangled the code something fierce.
Here is the code (as it is… not fancy and I really over comment. It helps me. Hopefully it won’t confuse to much):
mainWindow.techAdd1Popup.Enabled = false
mainWindow.techAdd1Popup.InitialValue = "-"
// ok I have declared the timer events in the app.
// so let's do the time
Var d As New MessageDialog // declare the MessageDialog object
Var b As MessageDialogButton // for handling the result
app.endIncidentTime = new date
app.endIncidentTime = DateTime.Now
dim replacednameTextField as string // to hold the information after removing ' quotes
dim replacednotesTextArea as string // to hold the information after removing ' quotes
mainWindow.endTextField.text = str(app.endIncidentTime)
//check to see if startTime is missing. If it is, don't let them save. They will have to re-enter their data. Teach them, I will!
// create a dialog box later so that they can choose to save their entered information... mind since the time is autogenerated, it still won't be 100% correct.
// maybe I'll fix that by allowing them to enter a start time and mark that this wasn't autogenerated for continuity's sake.
if mainWindow.startTextfield.text = "" then
// change this to a message dialog to give them the option of clearing everything out, or saving and restarting
d.Icon = MessageDialog.GraphicCaution // display warning icon
d.ActionButton.Caption = "Retain all but Start and End time"
d.CancelButton.Visible = True // show the Cancel button
d.AlternateActionButton.Visible = True // show the "Don't Save" button
d.AlternateActionButton.Caption = "Delete all Information"
d.Message = "You are missing the start Time, which means time worked will be incorrect"
d.Explanation = "Chose one of the options displayed in the buttons. "
// now enable the starttime and endtime so the person can enter their data
// but append "Manually entered" so they know it is not autoentered so can't be considered "true"
startTextfield.Enabled = true
endTextField.Enabled = true
b = d.ShowModal // display the dialog
Select Case b // determine which button was pressed.
Case d.ActionButton
// use these for the conversion
var manualStartTime as Xojo.Core.Date
var manualEndTime as Xojo.Core.Date
var convertedToTextStartTime as Text
var convertedToTextEndTime as Text
'mainWindow.groupPopupMenu.SelectedRowIndex = -1
'mainWindow.nameTextField.text =""
mainWindow.startTextfield.text = ""
mainWindow.endTextField.text = ""
'mainWindow.notesTextArea.text = ""
'mainWindow.techAdd1Popup.SelectedRowIndex = -1
'assistingTechCell.text = ""
'assistingTechOffice.text = ""
startTextfield.TextColor = RGB(255,0,0)
endTextField.TextColor = RGB(255,0,0)
convertedToTextStartTime = startTextfield.text.ToText
convertedToTextEndTime = endTextField.text.toText
Case d.AlternateActionButton
mainWindow.endTextField.text = ""
mainWindow.groupPopupMenu.SelectedRowIndex = -1
mainWindow.nameTextField.text =""
mainWindow.startTextfield.text = ""
mainWindow.endTextField.text = ""
mainWindow.notesTextArea.text = ""
mainWindow.techAdd1Popup.SelectedRowIndex = -1
assistingTechCell.text = ""
assistingTechOffice.text = ""
startTextfield.TextColor = RGB(255,0,0)
endTextField.TextColor = RGB(255,0,0)
Case d.CancelButton
// user pressed Cancel
End Select
return
else
end if
// now that the end button has been pushed, get the difference
app.timeDifference = app.endIncidentTime.TotalSeconds - app.startIncidentTime.TotalSeconds
//before you write into the database, make sure that the textfields (if the have ' single quotes are changed to _ or
//it will mess up and not write properly
replacednameTextField = nameTextField.text.Replace("'","_")
replacednotesTextArea = notesTextArea.text.Replace ("'","_")
// this is done to deal with end of line issues in an sqlite database. We check to see what version of OS is being run on, and change accordingly
#if TargetMacOS then
replacednotesTextArea = notesTextArea.text.ReplaceLineEndings(EndOfLine.macOS)
#else
replacednotesTextArea = notesTextArea.text.ReplaceLineEndings(EndOfLine.Windows)
#EndIf
dim sql as string // holder for SQL command
sql = "INSERT INTO Activity (groupType, Name, startTIme, endTime, Notes, seconds, minutes, hours, tech3, tech2, tech1) VALUES ('"+groupPopupMenu.getString+"','"+replacednameTextField+"','"+startTextfield.text+"','"+endTextField.text+"','"+replacednotesTextArea+"','"+app.timeDifference.ToString+"','"+str(app.timeDifference/60)+"','"+str(app.timeDifference / 3600)+"','"+techAdd1Popup.getString+"','"+assistingTechOffice.text+"','"+assistingTechCell.text+"')"
sqlDatabaseCommands(sql)
Regards