#1 2016-02-02 17:52:19

datadon
Member
Registered: 2015-04-23
Posts: 108

Arrays to Variables

Most of the selector controls if not all of them use the array protocal to store the list.  I think I need some clarification on how to use these items.

I think I understand how to get the list into the array and also get them out using the GetOptions (I think).  But what to do with them at that point?

Can you show some code that would take me from getting my selected item in a dropdown control all the way to where it is stored as a variable that I can use.  I may be making a lot more of this than it is but would like to see the right way to do it.

Also the Index, what is that all about and what is correct configuration if it is required.

:-)   It is always something hey David?

Offline

#2 2016-02-02 18:38:12

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Arrays to Variables

Hello Donald,

Yes; certain controls base their functionallity in Array variables. This is good, because, we can creates Array variables too, and uses all the Arrays related actions for both control's Array variables and our own Array variables.

For example, if we are talking about Select controls, we always can get the currently selected item using a code like this:

ArrayGetItem "[Select1.Items]" "[Select1.ItemIndex]" "[Result]"

The first argument is the Array from we want to get an specific item. In this case such Array is the Select control "Items" Array, but remember we can use this same action with any Array variable.

The second argument is the "index" we want to get from the Array. The Arrays stores the items in a zero based index, so the first item is the "0" (zero), the second item is the "1", and so on. The Select controls offer to us the "ItemIndex" variable, which stores the currently selected item in the control.

The third argument is the result variable, that is, the variable which stores the item we get from the specified Array.

Above we say the Select's "ItemIndex" stores the currently selected item in the control, and, we also can write this variable in order to select an item programatically, just by using the SetVar action:

SetVar "[Select1.ItemIndex]" "0" "Number"

The above action establish the first item in the Array (zero indexed, remember) as the selected item in the Select control.

As I said above, we can play with all the Arrays related actions, so, for example, we can add a new item at the end of a Select control:

ArrayPush "[Select1.Items]" "My new Item"

We can add a new item at the start of a Select control:

ArrayUnshift "[Select1.Items]" "My new Item"

We can concat a "Select2" control items into a "Select1" control items:

ArrayConcat "[Select1.Items]" "[Select2.Items]" [Select1.Items]"

We can remove the last element form of a Select control:

ArrayPop "[Select1.Items]" "[Result]"

Or remove the first element:

ArrayShift "[Select1.Items]" "[Result]"

And finally we can continue using the other Array related actions to reverse the items, short them in various ways, search for items, etc., etc. You can start with the NewArray action in the help file and continue scrolling down for other Arrays related actions.

If you have any further question just post it Donald. smile

Offline

#3 2016-02-02 19:20:46

datadon
Member
Registered: 2015-04-23
Posts: 108

Re: Arrays to Variables

Excellent David.  That is very useful info.  Thanks

Offline

#4 2016-02-02 20:31:14

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Arrays to Variables

You're welcome sir! smile

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.