hugodiz / TextUtilsDNA

High-performance text wrangling and fuzzy lookup functions for Excel, powered by .NET via ExcelDNA
MIT License
7 stars 1 forks source link

TEXTSPLIT(..., RESUB(...)) composition giving #VALUE! even with valid arguments #2

Closed hugodiz closed 3 years ago

hugodiz commented 3 years ago

Composing =TEXSPLIT(..., RESUB(...)) returns #VALUE! in situations where computing RESUB(...) in cell A, and then using TEXTSPLIT(..., cell A) (instead of doing it all in one step using formula composition), works! So 1 step fails, 2 step works (almost as if it were a timing issue, which seems odd). Could it have to do with implicit conversions of .NET / Excel data types? Maybe the return value of RESUB is not actually the correct type for input of the 3rd argument of TEXTSPLIT, however after RESUB lands on a cell, using that range as the 3rd argument of TEXTSPLIT then works ok.

Attached excel workbook reproduces the error

To do - debug with Visual Studio

BUG#2.xlsx

hugodiz commented 3 years ago

Fixed with commit 43510d182aafb2795e4b0c16d493a7b0a106f661

Using Object as input type of TEXTSPLIT and UNPACK arguments was causing problems when composing multiple TextUtilsDNA functions directly, because for instance, RESUB returns an Object(,) array even if if just contains 1 value. Then TEXTSPLIT thinks it has been fed an array, and input validation fails because the input should be scalar. Therefore, I streamlined TEXTSPLIT and UNPACK to assume instead that their main input is an object(,), but then impose that the GetLength(0) and GetLength(1) must be 1. It is a more general / robust way to impose a "scalar" input. The performance overhead is not important because UNPACK is very lightweight, and the intention is to allow TEXTSPLIT accept true array inputs as a future feature, and vectorized operations should be favoured anyway whenever .NET performance is at steak for these functions.