Converting the value in a listbox cell to a datetime

Hi All.

Running into a little issue here, and hopefully someone can spot my error.

I run a code block that needs the date time, from a cell in a listbox to be put into a variable for the current date and time. (It isn’t REALLY the current date and time) but the value of the cell.

If I do

theNextRunDateTime = DateTime.FromString(“2022-May-12”)

The program runs just fine. Doesn’t mean my logic is right but the code still compiles.

If I do THIS

theNextRunDateTime = DateTime.FromString(window1.ListBox1.LastAddedRowIndex,4)

I get the error

Window1.PopupMenu1.SelectionChanged, line 92
Expected (String, Locale, TimeZone), but these arguments are (Integer, Int64, Nil).
theNextRunDateTime = DateTime.FromString(window1.ListBox1.LastAddedRowIndex,4)

Can anyone see what I am doing wrong?


I don’t see that you actually get the string from the listbox.

As a general rule, simplify your code first. Get the string from the listbox and then convert to a DateTime. That will generally make it more clear than trying to do everything in one line of code.

1 Like

CellTextAt is missing from your code (and adjust it to use).

1 Like

its somehow
.FromString(Row, Column)

Best would be to not try to read such data at all from user interface representation.

Your just creating fail point that is not needed by doing that.

So for example in good app that you want to have maintainable and fewer fail points then you would have it something like this:

You have some data model representing your data. Lets say your list box is displaying persons.

  1. You have person class. (The model for your data).
  2. You fill the relevant columns in your list box and treat it only as visual representation.
  3. You put the Person class instance in the CellTag.

So when you want to get anything from person for given listbox row then you simply access the CellTag, and get the Person class instance, from that you get for example Person.Birthdate.

1 Like

Try this

theNextRunDateTime = DateTime.FromString(window1.ListBox1.CellTextAt(window1.ListBox1.LastAddedRowIndex,4))

I’ll give that a whirl.

That‘s the exact opposite to what Björn wrote.


Yep. But it was the down and dirty answer he was looking for. He can always go back and create a class to do it as Bjorn laid out when he has time and if he cares whether it is a future failure point.

1 Like