Nil date error

I don’t understand the problem.

It works with DateTime.Now
I can’t find out.

  rowsFound = app.db.SelectSQL("select * from Dokumente where Datum > '01.01.2010' order by Datum asc")
  For Each row as DatabaseRow in rowsFound
    If rowsFound <> Nil Then
      If row.Column("Datum").Value <> Nil Then
        MessageBox(row.Column("Datum")) // shows first date from Dokumente correctly
          var dat As Date = Row.Column("Datum").DateValue // No Errors in Code but crashes with dat = NIL // 'DateTime.Now' works!
        Label_date.Text = dat.SQLDate // Convert to yyyy-mm-dd and set to 'Label_date.Text'
        ListBox1.AddRow(row.Column( "Bezeichnung").StringValue, Label_date.text, row.Column( "Name").StringValue, row.Column( "Betrag").StringValue, row.Column( "ID").StringValue) // OK
        ListBox1.AddRow ""
      End If
    End if
Catch error as DatabaseException
End Try

Hi Oliver, welcome to the forums.

Is better if you create a new topic instead of asking on a topic that is already marked as solved. People may miss your problem. Maybe a moderator can split your question (and my comment) into its own thread.

What version of Xojo are you using?

It is not recommended to use MessageBox as a debugging tool. From the documentation:


You should avoid using MessageBox for displaying debugging messages. The displaying of the Message Box will alter event order and may give unexpected results. Instead use the Debugger, System.DebugLog or your own logging mechanism.

Can you comment that line and try again (you can use DebugLog if you want). Maybe that will help.

Another thing you can do is put var dat as new date before the For Each row...

Do you need to use Date or can you use DateTime?

Please try it with the addition of “new” (see date in documentation)

var dat As New Date

Your messageBox shows that the string value of Datum is 18.11.2023 which is a localised date, not convertible directly into a date variable. I would either use DateTime where one of the constructors allows you to read localised string dates or convert the Datum column to contain unlocalised data. Makes it easier to have the Select really only show valid documents because the comparison string starts with the year.

And yes, maybe like in the other thread wrap a check for Nil into that method.

1 Like

As Ulrich said, if your dates are saved as 18.11.2023 then you will need to change your code from:

to something like:

Var dat As datetime = DateTime.FromString(Row.Column("Datum").StringValue, Locale.Current)

Note: if you use the application with other locale (US for example) your stored dates of 18.11.2023 will cause an error. Maybe you want to review the documentation about locale and change Locale.Current to one that match the saved database date.

Well. Thanx AllbertoD. This works now! Great.
I have to take a closer look at this again. :innocent: The MessageBox (System.Device.Model) gets an Error.

It’s not easy after more than 30 Years FileMaker … :woozy_face:
Every answer here has helped me a little further. :+1:

Thank You All

It looks like you are creating a Desktop application and the System.Device is for Mobile only.

The IDE give us hints about what is available and if you type System.d you can see that Device is not an option for a Desktop application: