Multidimensional array issue
David V Glasgow
dvglasgow at gmail.com
Tue Mar 9 06:37:51 EST 2021
Er, I think I have just reached the fourth level of array un-enlightenment.
Wait!…. I can see the cyberverse! SCHLOOOooooppp!-ting!
> On 3/8/21 5:36 PM, Bob Sneidar via use-livecode 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
>
> --
> Phil Davis
> 503-307-4363
>
>
> _______________________________________________
> 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