Some User Defined Array Functions
aAppend() - Can fill an empty array and adds items to the end of the array.
aInsert() - Inserts a new item anywhere in the array except the end.
aMerge() - Merges two separate arrays.
aRemove() - Removes an array item.
aReplace() - Replaces an item in an array with a new item.
aSwap() - Swaps two items in an array.
Function Calls
aAppend(concat(yourArray), "newItem")
aInsert(concat(yourArray), "aryItem", "newItem")
aMerge(concat(yourArray1), concat(yourArray2)
aRemove(concat(yourArray), "aryItem")
aReplace(concat(yourArray), "aryItem", "newItem")
aSwap(concat(yourArray), "aryItem1", "aryItem2")
Function Definitions
function aAppend(ary : text,newItem : text) do
if count(ary) > 0 then
split(replace(ary, ", ", ",") + "," + newItem, ",")
else
split(newItem, ",")
end
end;
function aInsert(ary : text,insLoc : text,insItem : text) do
if count(split(ary, ",")) > 0 then
if contains(ary, insLoc) then
split(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")
else
alert("aInsert( ) : " + insLoc + " is not in the array!");
split(replace(ary, ", ", ","), ",")
end
else
alert("aInsert( ) : Can't insert into an empty array! Use aAppend( )")
end
end;
function aMerge(ary1 : text,ary2 : text) do
split(replace(ary1 + "," + ary2, ", ", ","), ",")
end;
function aRemove(ary : text,delItem : text) do
if count(split(ary, ",")) > 0 then
if contains(ary, delItem) then
if index(ary, delItem) + length(delItem) != length(ary) then
split(replace(replace(ary, delItem + ", ", ""), ", ", ","), ",")
else
split(replace(replace(ary, delItem, ""), ", ", ","), ",")
end
else
alert("aRemove( ) : " + delItem + " is not in the array!");
split(replace(ary, ", ", ","), ",")
end
else
alert("aRemove( ) : The array is empty!")
end
end;
function aReplace(ary : text,fromItem : text,toItem : text) do
if contains(ary, fromItem) then
split(replace(replace(ary, fromItem, toItem), ", ", ","), ",")
else
alert("aReplace( ) : " + fromItem + " is not in the array!");
split(replace(ary, ", ", ","), ",")
end
end;
function aSwap(ary : text,itmOne : text,itmTwo : text) do
let myString := "";
if count(split(ary, ",")) > 2 then
if contains(ary, itmOne) then
if contains(ary, itmTwo) then
let itmTmp := "#%$";
ary := replace(ary, itmOne, itmTmp);
ary := replace(ary, itmTwo, itmOne);
ary := replace(ary, itmTmp, itmTwo);
split(replace(ary, ", ", ","), ",")
else
alert("aSwap( ) : " + itmTwo + " is not in the array!");
split(replace(ary, ", ", ","), ",")
end
else
alert("aSwap( ) : " + itmOne + " is not in the array!");
split(replace(ary, ", ", ","), ",")
end
else
alert("aSwap( ) : There must be 2 or more items in the array!");
split(replace(ary, ", ", ","), ",")
end
end
23 replies
-
Thanks for sharing
-
You bet. If you or anyone make a mod or have a suggestion, please post it.
-
Something I found very helpful is that functions defined in "Global scrip definitions" can be called in the console.
-
Shouldn't the 'if' statement in aAppend be similar to the other functions?
count() is listed as a array fucntions, but ary is text.
function aAppend(ary : text,newItem : text) do
if count(ary) > 0 thenshouldn't it be
if count(split(ary, ",")) > 0 then
-
Blackie, for the sake of consistency yes. But, all it’s checking for is whether the string is empty or not. The result will be either 0 or 1.
Looks like I’ll be out of commission for a while. The result of a sequence of events that ended with my laptop falling to the floor.
-
An external monitor will have to do for now... I reposted all of the functions because it's a pain to compare what's changed. There is still quite a bit of error checking and validating that can be done. This update addresses blackie's question, returns an unaltered array when there is an error and changes the count test in aSwap from > 2 to >= 2.
function aAppend(ary : text,newItem : text) doif length(newItem) != 0 thenif count(split(ary, ",")) > 0 thensplit(replace(ary, ", ", ",") + "," + newItem, ",")elsesplit(newItem, ",")endelsealert("aAppend( ) : New array item can't be empty!");split(replace(ary, ", ", ","), ",")endend;function aInsert(ary : text,insLoc : text,insItem : text) doif count(split(ary, ",")) > 0 thenif contains(ary, insLoc) thensplit(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")elsealert("aInsert( ) : " + insLoc + " is not in the array!");split(replace(ary, ", ", ","), ",")endelsealert("aInsert( ) : Can't insert into an empty array! Use aAppend( )");split(replace(ary, ", ", ","), ",")endend;function aMerge(ary1 : text,ary2 : text) dosplit(replace(ary1 + "," + ary2, ", ", ","), ",")end;function aRemove(ary : text,delItem : text) doif count(split(ary, ",")) > 0 thenif contains(ary, delItem) thenif index(ary, delItem) + length(delItem) != length(ary) thensplit(replace(replace(ary, delItem + ", ", ""), ", ", ","), ",")elsesplit(replace(replace(ary, delItem, ""), ", ", ","), ",")endelsealert("aRemove( ) : " + delItem + " is not in the array!");split(replace(ary, ", ", ","), ",")endelsealert("aRemove( ) : The array is empty!");split(replace(ary, ", ", ","), ",")endend;function aReplace(ary : text,fromItem : text,toItem : text) doif contains(ary, fromItem) thensplit(replace(replace(ary, fromItem, toItem), ", ", ","), ",")elsealert("aReplace( ) : " + fromItem + " is not in the array!");split(replace(ary, ", ", ","), ",")endend;function aSwap(ary : text,itmOne : text,itmTwo : text) doif count(split(ary, ",")) >= 2 thenif contains(ary, itmOne) thenif contains(ary, itmTwo) thenlet itmTmp := "#%$";ary := replace(ary, itmOne, itmTmp);ary := replace(ary, itmTwo, itmOne);ary := replace(ary, itmTmp, itmTwo);split(replace(ary, ", ", ","), ",")elsealert("aSwap( ) : " + itmTwo + " is not in the array!");split(replace(ary, ", ", ","), ",")endelsealert("aSwap( ) : " + itmOne + " is not in the array!");split(replace(ary, ", ", ","), ",")endelsealert("aSwap( ) : There must be 2 or more items in the array!");split(replace(ary, ", ", ","), ",")endend -
Interesting behavior... The issue in this thread, https://ninoxdb.de/en/forum/technical-help-5ab8fe445fe2b42b7dd39ee7/this-is-driving-me-crazy-5c1c7d62cf005e2aa074793e, isn't a problem if the first function in the "Global script definitions" is called by another function in there.
Three new functions...
aIsEmpty() - Tests for an empty array and is used by some of the other functions.
aClear() - Returns an empty array.
aGetIndex() - Returns the index number of the passed array item.
Function Calls
aIsEmpty(concat(yourArray))aClear(concat(yourArray))aGetIndex(concat(yourArray), "aryItem")Function Definitions
I've updated most of the function definitions for cleanup and better validation.
function aIsEmpty(ary : text) dolet myArray := split(replace(ary, ", ", ","), ",");if count(myArray) > 0 then false else true endend;function aAppend(ary : text,newItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if length(newItem) != 0 thenif not aIsEmpty(ary) thenmyArray := split(replace(ary, ", ", ",") + "," + newItem, ",")elsemyArray := split(newItem, ",")endelsealert("aAppend( ) : New array item can't be empty!")end;myArrayend;function aClear(ary : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenary := "";myArray := split(ary, ",")end;myArrayend;function aGetIndex(ary : text,aryItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");let aryIndex := 0;while aryItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;if aryIndex < count(myArray) thenaryIndexelsealert("aGetIndex( ) : """ + aryItem + """ is not in the array!");-1endend;function aInsert(ary : text,insLoc : text,insItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := 0;while insLoc != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;if aryIndex < count(myArray) thenmyArray := split(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")elsealert("aInsert( ) : """ + insLoc + """ is not in the array!")endelsealert("aInsert( ) : Can't insert into an empty array! Use aAppend( )")end;myArrayend;function aMerge(ary1 : text,ary2 : text) dolet myArray := split(replace(ary1 + "," + ary2, ", ", ","), ",");myArrayend;function aRemove(ary : text,delItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := 0;while delItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;if aryIndex < count(myArray) thenif index(ary, delItem) + length(delItem) != length(ary) thenmyArray := split(replace(replace(ary, delItem + ", ", ""), ", ", ","), ",")elsemyArray := split(replace(replace(ary, delItem, ""), ", ", ","), ",")endelsealert("aRemove( ) : """ + delItem + """ is not in the array!")endelsealert("aRemove( ) : The array is empty!")end;myArrayend;function aReplace(ary : text,fromItem : text,toItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := 0;while fromItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;if aryIndex < count(myArray) thenmyArray := split(replace(replace(ary, fromItem, toItem), ", ", ","), ",")elsealert("aReplace( ) : """ + fromItem + """ is not in the array!")endelsealert("aReplace( ) : The array is empty!")end;myArrayend;function aSwap(ary : text,itmOne : text,itmTwo : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif count(myArray) >= 2 thenlet aryIndex1 := 0;while itmOne != item(myArray, aryIndex1) and aryIndex1 < count(myArray) doaryIndex1 := aryIndex1 + 1end;if aryIndex1 < count(myArray) thenlet aryIndex2 := 0;while itmTwo != item(myArray, aryIndex2) and aryIndex2 < count(myArray) doaryIndex2 := aryIndex2 + 1end;if aryIndex2 < count(myArray) thenlet itmTmp := "#%$";ary := replace(ary, itmOne, itmTmp);ary := replace(ary, itmTwo, itmOne);ary := replace(ary, itmTmp, itmTwo);myArray := split(replace(ary, ", ", ","), ",")elsealert("aSwap( ) : """ + itmTwo + """ is not in the array!")endelsealert("aSwap( ) : """ + itmOne + """ is not in the array!")endelsealert("aSwap( ) : There must be 2 or more items in the array!")endelsealert("aSwap( ) : The array is empty!")end;myArrayend -
I missed something obvious last night. aGetIndex() can be used to replace the while loops in aInsert(), aRemove(), aReplace() and aSwap(). Also, aGetIndex() and aIsEmpty() should be defined before any of the other UDF array functions.
function aGetIndex(ary : text,aryItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");let aryIndex := 0;while aryItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;aryIndexend;function aInsert(ary : text,insLoc : text,insItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := aGetIndex(ary, insLoc);if aryIndex < count(myArray) thenmyArray := split(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")elsealert("aInsert( ) : """ + insLoc + """ is not in the array!")endelsealert("aInsert( ) : Can't insert into an empty array! Use aAppend( )")end;myArrayend;function aRemove(ary : text,delItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := aGetIndex(ary, delItem);if aryIndex < count(myArray) thenif index(ary, delItem) + length(delItem) != length(ary) thenmyArray := split(replace(replace(ary, delItem + ", ", ""), ", ", ","), ",")elsemyArray := split(replace(replace(ary, delItem, ""), ", ", ","), ",")endelsealert("aRemove( ) : """ + delItem + """ is not in the array!")endelsealert("aRemove( ) : The array is empty!")end;myArrayend;function aReplace(ary : text,fromItem : text,toItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := aGetIndex(ary, fromItem);if aryIndex < count(myArray) thenmyArray := split(replace(replace(ary, fromItem, toItem), ", ", ","), ",")elsealert("aReplace( ) : """ + fromItem + """ is not in the array!")endelsealert("aReplace( ) : The array is empty!")end;myArrayend;function aSwap(ary : text,itmOne : text,itmTwo : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif count(myArray) >= 2 thenlet aryIndex1 := aGetIndex(ary, itmOne);if aryIndex1 < count(myArray) thenlet aryIndex2 := aGetIndex(ary, itmTwo);if aryIndex2 < count(myArray) thenlet itmTmp := "#%$";ary := replace(ary, itmOne, itmTmp);ary := replace(ary, itmTwo, itmOne);ary := replace(ary, itmTmp, itmTwo);myArray := split(replace(ary, ", ", ","), ",")elsealert("aSwap( ) : """ + itmTwo + """ is not in the array!")endelsealert("aSwap( ) : """ + itmOne + """ is not in the array!")endelsealert("aSwap( ) : There must be 2 or more items in the array!")endelsealert("aSwap( ) : The array is empty!")end;myArrayend -
One more small adjustment. aInsert() can now be used append to an empty array or existing array. Call the function like this...
aInsert(concat(yourArray), "", "newItem")function aInsert(ary : text,insLoc : text,insItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if insLoc != "" thenlet aryIndex := aGetIndex(ary, insLoc);if aryIndex < count(myArray) thenmyArray := split(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")elsealert("aInsert( ) : """ + insLoc + """ is not in the array!")endelsemyArray := aAppend(ary, insItem)end;myArrayend;It simply calls the aAppend() function instead of giving the error message.
-
This code fixes string replace errors in aReplace() and aSwap(). For those who are interested, these functions are, for the most part, manipulating strings to simulate array functions that are available in other programming languages. The problem fixed here is one where an item being replaced or swapped is a substring of more than one items.
For example, if you replace "Test 1" with "Hello" in an array with "Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6", "Test 7", "Test 8", "Test 9", "Test 10", "Test 11" the items "Test 10" and "Test 11" would be changed to "Hello0" and "Hello1".
function aReplace(ary : text,fromItem : text,toItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenlet aryIndex := aGetIndex(ary, fromItem);if aryIndex < count(myArray) thenif index(ary, fromItem) + length(fromItem) != length(ary) thenmyArray := split(replace(replace(ary, fromItem + ", ", toItem + ", "), ", ", ","), ",")elsemyArray := split(replace(replace(ary, fromItem, toItem), ", ", ","), ",")endelsealert("aReplace( ) : """ + fromItem + """ is not in the array!")endelsealert("aReplace( ) : The array is empty!")end;myArrayend;function aSwap(ary : text,itmOne : text,itmTwo : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif count(myArray) >= 2 thenlet aryIndex1 := aGetIndex(ary, itmOne);if aryIndex1 < count(myArray) thenlet aryIndex2 := aGetIndex(ary, itmTwo);if aryIndex2 < count(myArray) thenlet itmTmp := "#%$";if index(ary, itmOne) + length(itmOne) != length(ary) thenary := replace(ary, itmOne + ", ", itmTmp + ", ")elseary := replace(ary, itmOne, itmTmp)end;if index(ary, itmTwo) + length(itmTwo) != length(ary) thenary := replace(ary, itmTwo + ", ", itmOne + ", ")elseary := replace(ary, itmTwo, itmOne)end;ary := replace(ary, itmTmp, itmTwo);myArray := split(replace(ary, ", ", ","), ",")elsealert("aSwap( ) : """ + itmTwo + """ is not in the array!")endelsealert("aSwap( ) : """ + itmOne + """ is not in the array!")endelsealert("aSwap( ) : There must be 2 or more items in the array!")endelsealert("aSwap( ) : The array is empty!")end;myArrayend -
aMove() - Moves an array item to the top, bottom or between items of the array. It must be defined after aGetIndex(), aIsEmpty(), aAppend(), aInsert() and aRemove() to work as it is defined here.
Function Calls
aMove(concat(yourArray), "", "moveItem") - Moves the item to the end of the array.aMove(concat(yourArray), "aryItem", "moveItem") - Moves the item anywhere else in the array.Function Definition
function aMove(ary : text,movLoc : text,movItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif movLoc != "" thenlet aryIndex := aGetIndex(ary, movLoc);if aryIndex < count(myArray) thenmyArray := aRemove(ary, movItem);myArray := aInsert(concat(myArray), movLoc, movItem)elsealert("aMove( ) : """ + movLoc + """ is not in the array!")endelsemyArray := aRemove(ary, movItem);myArray := aAppend(concat(myArray), movItem)endelsealert("aMove( ) : The array is empty!")end;myArrayend; -
aContains() - Returns a boolean value. This replaces aGetIndex() in UDF's aInsert(), aRemove(), aMove(), aReplace() and aSwap(). Also, the aMove() function definition is updated to validate movItem.
Function Call
aContains(concat(yourArray), "aryItem")Function Definitions
function aContains(ary : text,aryItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");let aryIndex := 0;while aryItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;if aryIndex < count(myArray) thentrueelsefalseendend;function aGetIndex(ary : text,aryItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");let aryIndex := 0;while aryItem != item(myArray, aryIndex) and aryIndex < count(myArray) doaryIndex := aryIndex + 1end;aryIndexend;function aIsEmpty(ary : text) dolet myArray := split(replace(ary, ", ", ","), ",");if count(myArray) > 0 then false else true endend;function aAppend(ary : text,newItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if length(newItem) != 0 thenif not aIsEmpty(ary) thenmyArray := split(replace(ary, ", ", ",") + "," + newItem, ",")elsemyArray := split(newItem, ",")endelsealert("aAppend( ) : New array item can't be empty!")end;myArrayend;function aClear(ary : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenary := "";myArray := split(ary, ",")end;myArrayend;function aInsert(ary : text,insLoc : text,insItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if insLoc != "" thenif aContains(ary, insLoc) thenmyArray := split(replace(replace(ary, insLoc, insItem + "," + insLoc), ", ", ","), ",")elsealert("aInsert( ) : """ + insLoc + """ is not in the array!")endelsemyArray := aAppend(ary, insItem)end;myArrayend;function aMerge(ary1 : text,ary2 : text) dolet myArray := split(replace(ary1 + "," + ary2, ", ", ","), ",");myArrayend;function aRemove(ary : text,delItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif aContains(ary, delItem) thenif index(ary, delItem) + length(delItem) != length(ary) thenmyArray := split(replace(replace(ary, delItem + ", ", ""), ", ", ","), ",")elsemyArray := split(replace(replace(ary, delItem, ""), ", ", ","), ",")endelsealert("aRemove( ) : """ + delItem + """ is not in the array!")endelsealert("aRemove( ) : The array is empty!")end;myArrayend;function aMove(ary : text,movLoc : text,movItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif movLoc != "" thenif aContains(ary, movLoc) thenif aContains(ary, movItem) thenmyArray := aRemove(ary, movItem);myArray := aInsert(concat(myArray), movLoc, movItem)elsealert("aMove( ) : """ + movItem + """ is not in the array!")endelsealert("aMove( ) : """ + movLoc + """ is not in the array!")endelseif aContains(ary, movItem) thenmyArray := aRemove(ary, movItem);myArray := aAppend(concat(myArray), movItem)elsealert("aMove( ) : """ + movItem + """ is not in the array!")endendelsealert("aMove( ) : The array is empty!")end;myArrayend;function aReplace(ary : text,frmItem : text,toItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif aContains(ary, frmItem) thenif index(ary, frmItem) + length(frmItem) != length(ary) thenmyArray := split(replace(replace(ary, frmItem + ", ", toItem + ", "), ", ", ","), ",")elsemyArray := split(replace(replace(ary, frmItem, toItem), ", ", ","), ",")endelsealert("aReplace( ) : """ + frmItem + """ is not in the array!")endelsealert("aReplace( ) : The array is empty!")end;myArrayend;function aSwap(ary : text,itmOne : text,itmTwo : text) dolet myArray := split(replace(ary, ", ", ","), ",");if not aIsEmpty(ary) thenif count(myArray) >= 2 thenif aContains(ary, itmOne) thenif aContains(ary, itmTwo) thenlet itmTmp := "#%$";if index(ary, itmOne) + length(itmOne) != length(ary) thenary := replace(ary, itmOne + ", ", itmTmp + ", ")elseary := replace(ary, itmOne, itmTmp)end;if index(ary, itmTwo) + length(itmTwo) != length(ary) thenary := replace(ary, itmTwo + ", ", itmOne + ", ")elseary := replace(ary, itmTwo, itmOne)end;ary := replace(ary, itmTmp, itmTwo);myArray := split(replace(ary, ", ", ","), ",")elsealert("aSwap( ) : """ + itmTwo + """ is not in the array!")endelsealert("aSwap( ) : """ + itmOne + """ is not in the array!")endelsealert("aSwap( ) : There must be 2 or more items in the array!")endelsealert("aSwap( ) : The array is empty!")end;myArrayend -
It's not easy being the only debugger
A fix for aInsert() and another version of aContains(). If you want to see the error for aInsert() you can paste this in the console...
let a1 := [""];for i in range(1, 21) doa1 := aAppend(concat(a1), "Test " + i)end;a1 := aInsert(concat(a1), "Test 1", "Hello");a1function aInsert(ary : text,insLoc : text,insItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if insLoc != "" thenif aContains(ary, insLoc) thenmyArray := split(replace(replace(ary, insLoc + ",", insItem + "," + insLoc + ","), ", ", ","), ",")elsealert("aInsert( ) : """ + insLoc + """ is not in the array!")endelsemyArray := aAppend(ary, insItem)end;myArrayend;This version of aContains() calls aGetIndex() so aGetIndex() must be defined before aContains() for this to work.
function aContains(ary : text,aryItem : text) dolet myArray := split(replace(ary, ", ", ","), ",");if aGetIndex(ary, aryItem) < count(myArray) thentrueelsefalseendend; -
aGetItem() - This function returns the array item of a given index.
Function Call
aGetItem(concat(yourArray), aryIndex)Function Definition
function aGetItem(ary : text,aryIndex : number) dolet myArray := split(replace(ary, ", ", ","), ",");if aryIndex >= 0 thenif aryIndex < count(myArray) thenitem(myArray, aryIndex)elsealert("aGetItem( ) : Index is out of range! Array length is " + count(myArray) + ".")endelsealert("aGetItem( ) : Index can't be less than 0!")endend; -
Ooops, brainfart! item(array, index) is already built-in. Sorry!
-
Hi Sean,
Great array function! Thanks! I’m using (the latest versions of) acontains and agetindex. If you call agetindex with concat(Myarray) as argument, it works ok!
If you call agetindex with Array1 as argument where you use let Array1 := concat(Myarray), then you always get 0 as return, independent of the index position in the array, which is wrong!
so
agetindex(concat(Myarray), Myitem) works!
But
Let Array1:= concat(Myarray);
agetindex(Array1, Myitem) doesnn’t!
i can’t figure out why behaviour is different.
Of course in both situations Myitem is present in the array, and not always on index position 0!!!
-
Hi dessein,
Thank you! I tested the function using a "preconcatenated" variable in the function and it worked. One thing I do see is you have "Let" instead of "let". Ninox language is case sensitive so that will make a difference. If that was just a typo in your post let me know.
-
Let is indeed a typo in my post.
i use let in my code. The only thing i can think of, the array is made up of “choice” type of items coming from a ninox table field Task.
code with issues:
let aTask := concat(Action.Task);
if aContains(aTask, "Sow") then
aGetIndex(aTask, "Sow") => always returns 0
else
null
endcode without issues:
if aContains(concat(Action.Task), "Sow") then
aGetIndex(concat(Action.Task), "Sow") => returns the correct index!!!
else
null
endit took we long time to find this “workaround...
-
Did you mean "Multiple choice" instead of "choice" type? I did some testing with the "Multiple choice" type and got the same result you did. It looks like the user-defined functions do not allow user variables as arguments. Even if you used (concat(Action.Task), but replaced "Sow" with a variable that contained "Sow" it would not work correctly. In this case I believe it would return an index 1 greater than the index of the last item in the array.
-
No, “choice” .
-
I'm pretty sure the "Choice" field type does not return an array.
-
To clarify: i use a table Succulent with a subtable Action. When on a particular Succulent record, the command Action.Task doesn’t return an array with all Action records? Altough concat(Action.Task) does give me a text string with all Action records with the Task field. E.g. Sow ,Repot , Transplant for that particular Succulent record.
-
I follow you now and, yes, you are correct. I thought you were using a "Choice" field type, but you are a linked table which would return an array of values.
Content aside
- 6 yrs agoLast active
- 23Replies
- 8414Views
