Code review - please :)

Could someone please tell me why the database file gets saved perfectly, BUT, the “File could not be created” error message still displays (even though there is obviously no error)??

[code] Dim source As FolderItem = SpecialFolder.ApplicationData.Child(“Snippets Data”).Child(“Snippets.db”)

If source <> Nil Then

Dim dlg as New SaveAsDialog
Dim f as FolderItem
dlg.InitialDirectory = SpecialFolder.Desktop
dlg.promptText = "File Details"
dlg.SuggestedFileName = "Snippets Database.db"
dlg.Title = "Export Snippets Database"
dlg.Filter = FileTypes1.SQLite
f = dlg.ShowModal()

if f <> Nil then
  If f.Exists Then f.delete
  source.CopyFileTo f
  if f.LastErrorCode <> 0 then
    MsgBox("File could not be created!")
    MainWindow.m.DeliverNotification( MainWindow.CreateMessage )
  end if
end If

MsgBox(“The snippets database seems to no longer exist?”)

end if[/code]

So what does f.LastErrorCode actually get set to?

Try replacing

if f.LastErrorCode <> 0 then


if source.LastErrorCode <> 0 then

Thanks - that worked, but I have no idea why?

I was advised to check for “LastErrorCode” before displaying the notification - that’s why I included that line of code.
How / where do I check for an error with f before displaying the notification??


It works because you are concerned about an error occurring when executing CopyFileTo which is called as a method of source, not f – f is just a parameter identifying the file the contents of source should be copied to.