StrCoalesce()

Started by JTaylor, March 28, 2019, 11:29:19 AM

Previous topic - Next topic

JTaylor

Assuming I haven't overlooked it a StrCoalesce() function would be handy.  Not sure why I hadn't thought to suggest it before but would save a lot of "IF" statements in certain situations.  Thanks.


Jim

td

What exactly would we wish this function to do?   For example, in SQL the coalesce function usually returns the first non-null expression in a list in most implementations.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Should have been a bit more specific.  Yes.  The same thing.   I process a lot of data, which you have probably figured out by now and working on something now where I have to extract a column and if it is blank then extract another for that value and so on.   Was thinking something like...

   value = StrCoalesce(ItemExtract(12,list,@TAB),ItemExtract(13,list,@TAB),ItemExtract(14,list,@TAB))

would be better than something like:

   value = ItemExtract(12,list,@TAB)
   If value == "" Then value = ItemExtract(13,list,@TAB)
   If value == "" Then value = ItemExtract(14,list,@TAB)


...and Yes, I know I could write a function to do the same.

Thanks.


Jim

td

I guess that if I were rolling my own, I would implement a UDF with a "for" loop.  Or if speed was critical, use a UDS with "for" loop unrolling optimization if the list was typically long enough to gain from unrolling.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade