I continue to be impressed :)

I was populating a listbox from a database today, and the compiler complained about an Nil object exception in my Shipment object - a date field. All fine, I began looking for a nice null coalescing operator; specifically something like VB.Net’s IIF.

Xojo doesn’t have that but I found that Xojo’s “If” operator is ternary. I never noticed that in the IDE and I’m super impressed.

Rather than doing something “long” like

If shipment.Received Is Nil Then Me.Cell(Me.LastIndex, 11) = "" Else Me.Cell(Me.LastIndex, 11) = shipment.Received.SQLDate.ToText End If

You can just do this; I find it much cleaner (which I realize is an opinion):

Me.Cell(Me.LastIndex, 11) =  If (shipment.Received Is Nil, "", shipment.Received.SQLDate.ToText)

It’s been around for quite a while :smiley:

I recently discovered this as well and I’m chagrined to know how long I overlooked it. Now my problem is that I forget to use it because I’m so used to it not being there…

Indeed. Personally I dislike it strongly.

Or just use SQL to modifiy it for you before Xojo even sees it.

[quote=450796:@Rob Hallock]

Me.Cell(Me.LastIndex, 11) =  If (shipment.Received Is Nil, "", shipment.Received.SQLDate.ToText)

This has been around, in one form or another, for a long time.

BCPL had it (called a conditional expression) as:

expr1 -> expr2, expr3

meaning evaluate expr1, and the value of the expression is then expr2 or expr3 as expr1 is true or false.

C (and then PHP, javascript) has it as:

expr1 ? expr2 : expr3

which I tend to find the most elegant.

I haven’t checked whether this existed before BCPL.