Multidimensional array issue

HENRY LOWE hlowe at me.com
Tue Mar 9 13:02:30 EST 2021


Thanks to all for your excellent discussion and suggestions.

To briefly restate the problem:


If tArray[“status”] does not contain a value

and

If tArray[“status”][“text”] contains a value


How do I determine if tArray[“status”] contains a value?


In the message box:

put "data" into tArray["key1"]["key2"]; answer the value of tArray["key1”] - returns EMPTY (so this works)

put "data" into tArray["key1"]["key2"]; answer tArray["key1”] is empty - returns FALSE (it should return true IMHO) 

put "data" into tArray["key1"]["key2"]; answer tArray["key1”] is an array - returns TRUE (so not helpful) 


Henry


> On Mar 8, 2021, at 5:36 PM, Bob Sneidar via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Are you testing for empty, or are you testing if there is a value in an array variable? If there is no key matching your array variable, LC will return an empty string. An empty string is a value. 
> 
> Mark is using a different method, seeing if a key of an array is itself an array. If bobtest ["value"] contains another array so that bobtest ["value"] ["anumber"] contains 1, then bobtest ["value"] is an array. If bobtest ["value"] contains 1 then it is not an array. 
> 
> But getting the value of bobtest ["value"] ["number"] will return empty whether or not bobtest '{value"] is an array. This is why Mark is testing for an array rather than the value. 
> 
> It seems a bit wonky, you might think, "Why not return an error?" But trust me, when you work with arrays, especially when it comes to datagrid data, this is the best course. 
> 
> Bob S
> 
> 
>> On Mar 8, 2021, at 16:25 , HENRY LOWE via use-livecode <use-livecode at lists.runrev.com> wrote:
>> 
>> Thanks Mark. There are two possible states:
>> 
>> tArray[“status”] holds a value and tArray[“status”][“text”] does not
>> 
>> or
>> 
>> tArray[“status”][“text”] holds a value and tArray[“status”] does not
>> 
>> 
>> My code is trying to do the following:
>> 
>> If tArray[“status”] does not hold a value then check if tArray[“status”][“text”] holds a value
>> 
>> 
>> The crux is how one reliably determines that an array member (e.g. tArray[“status”]) holds a value?
>> 
>> I would have assumed that if the array member does not hold a value then  - if tArray[member] is empty would always return true. However that does not appear to be the case if the array is multidimensional.
>> 
>> 
>> It appears that both tArray[“status”] is an array and tArray[“status”][“text”] is an array are true. Am I missing something about using this syntax?
>> 
>> Thanks,
>> 
>> Henry
>> 
>> 
>>> On Mar 8, 2021, at 3:56 PM, Mark Wieder via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> On 3/8/21 3:46 PM, HENRY LOWE via use-livecode wrote:
>>> 
>>>> I have often used the form 'if tArray[“key1”] is empty' to determine whether an array element hold a value but this breaks if tArray[“key1”][“key2”] holds a value.
>>> 
>>> Same here. Not that I've every liked that paradigm, just that it's been that way since life crawled out of the ocean.
>>> 
>>> However this should do the trick.
>>> 
>>> if tArray["status"] is an array then
>>> put tArray["status"]["text"] into tStatus
>>> else
>>> put tArray["status"] into tStatus
>>> end if
>>> 
>>> -- 
>>> Mark Wieder
>>> ahsoftware at gmail.com
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list