Hi,
My code below is used to delete a record from my database, and then update the listbox.
Can someone please tell me why when this code is run - the listbox does not change and I get the MsgBox error BUT when I quit and restart the app - the database entry has indeed been deleted as expected?
When I step through the code in the debugger - I get a NilObjectException.
I can not understand this because if the entry got deleted - how can rs=Nil??
I am having trouble jiggling my code around so that I still have error checking, without getting the error MsgBox?
[code]// DELETE THE SELECTED SNIPPET
dim sql, selected as string
selected=MainWindow.Listbox1.cell(MainWindow.Listbox1.listindex,0)
sql=“delete from Snippets where Title=’”+selected+"’"
rs=db.SQLSelect(sql)
db.Commit
if rs=nil then
msgbox(“Could not delete snippet.”)
self.close
else
// SUCCESS, SO UPDATE THE LISTBOX
MainWindow.Timer2.mode = MainWindow.Timer2.ModeSingle
end if[/code]
Christian - my code now looks as follows - but still has exactly the same problem - I am now lost:
[code] // DELETE THE SELECTED SNIPPET
dim sql, selected as string
selected=MainWindow.Listbox1.cell(MainWindow.Listbox1.listindex,0)
sql=“delete from Snippets where Title=’”+selected+"’"
rs=db.SQLSelect(sql)
db.Commit
if db.error then
msgbox(“database error!”)
self.close
else
// SUCCESS, SO UPDATE THE LISTBOX
MainWindow.Timer2.mode = MainWindow.Timer2.ModeSingle
end if[/code]
Tim,
I have got the code working, and thank you for your patience.
I apologise for my apparent ignorance, but I am still trying to grasp certain concepts, and at the moment my head is still all over the place as I recently found my mum dead!
I am concentrating on Xojo in order to distract myself.
Anyway - my code below now works - sorry for any annoyance I may have caused.
// DELETE THE SELECTED SNIPPET
dim sql, selected as string
selected=MainWindow.Listbox1.cell(MainWindow.Listbox1.listindex,0)
sql=“delete from Snippets where Title=’”+selected+"’"
db.SQLExecute(sql)
db.Commit
DeleteConfirmationWindow.close
// SUCCESS, SO UPDATE THE LISTBOX
MainWindow.Timer2.mode = MainWindow.Timer2.ModeSingle
The thing is I know you are trying to learn, which is very different from some of the others. But if you’re speeding so quickly and you don’t stop to think about the answers, you won’t retain the information for your future endeavors. I’m just concerned that you won’t learn what you wanted to.
Thanks Tim,
yes it was - I went to visit mum on mothers day and found her dead on the floor, and to make it worse - she had already been dead a few days!
At least I don’t have to worry about her being alone anymore.
Anyway - on a more cheerful note - thank you everyone for the help.