## How to retrieve an array element

Expand Messages
• Hi, I have an array, %MyArray% that contains 256 elements. If %ElementNum% contains the element # (1-256) that I want, how do I get that element out of the
Message 1 of 5 , Jul 24, 2009
Hi,

I have an array, %MyArray% that contains 256 elements.
If %ElementNum% contains the element # (1-256) that I want, how do I get
that element out of the array. I can't seem to locate the function to
do this.

Vance
• You just use numbers. An array of 256 items has 257 elements, the first being the number of elements ... so ... ^!Info ^%MyArray% would show all 256 elements
Message 2 of 5 , Jul 24, 2009
You just use numbers.

An array of 256 items has 257 elements, the first being the number of
elements ...

so ...

^!Info ^%MyArray% would show all 256 elements with the delimiter between
them ....
and
^!Info ^%MyArray0% would show the number of elements, in this case 256.

Then
^!Info ^%MyArray1% would show the first element,
^!Info ^%MyArray2% wold show the second and so forth,

so using a clip like this:
^!Set %count%="0"
^!Info Number of Elements: ^%MyArray^%count%%
:Loop
^!Info Element Number ^%count% is: ^%MyArray^%count%%
^!Inc %count%
^!If "^%count%" > "^%MyArray0%" End ELSE Loop

You should be able to show all elements and then each element ...
Caveat: not tested, wrote it by hand ....

Vance E. Neff wrote:
> Hi,
>
> I have an array, %MyArray% that contains 256 elements.
> If %ElementNum% contains the element # (1-256) that I want, how do I get
> that element out of the array. I can't seem to locate the function to
> do this.
>
> Vance
>
>
>
> ------------------------------------
>
> Fookes Software: http://www.fookes.com/
> NoteTab website: http://www.notetab.com/
> NoteTab Discussion Lists: http://www.notetab.com/groups.php
>
> ***
>
>
>
>
• Vance E. Neff (veneff@intouchmi.com) wrote (in part) (on 2009-07-24 at ... As Don showed in the sample clip code ... The key concept that took me a long time
Message 3 of 5 , Jul 24, 2009
Vance E. Neff (veneff@...) wrote (in part) (on 2009-07-24 at
13:15):
> I have an array, %MyArray% that contains 256 elements.
> If %ElementNum% contains the element # (1-256) that I want, how do I
> get
> that element out of the array. I can't seem to locate the function to
> do this.

As Don showed in the sample clip code ...
The key concept that took me a long time to understand when I first
tried to work with clip arrays is that each element of an array is
referred to by Notetab as a free-standing (and independent) variable.

IE ... most languages would refer to element 12 of MyArray as something
like ^%MyArray%(12) or ^%MyArray%[12]
Clipcode instead defers construction of final variable name until last
possible moment so if (in your example) ^%ElementNum% contains 12 and
the 12th element of the array is "asdf" you write (say)
^!Set %theElement%=^%MyArray^%MyElement%%
which is altered to
^!Set %theElement%=^%MyArray12%
and finally Clipcode executes:
^!Set %theElement%=asdf

If you step through your code with ^!SetDebug ON you can see this happening.

I'd never got around to finding a reason for constructing variable names
on the fly (though I think I saw a real-life example once here - perhaps
something in one of Sheri's clips?)

but for fun ... try this (her Make Instant Clip is useful here):

^!setdebug ON
^!Set %thePrefix%="pre"
^!Set %thePostfix%="post"
^!Set %theBase%="base"
^!Set %prebasepost%="this is very confusing%
; --Should display "this is very confusing%
^!info ^%^%thePrefix%^%theBase%^%thePostfix%%
; -- Can also be done on left side of assignment statement
^!Set %pre^%theBase%post%="will this work?"
^!info ^%^%thePrefix%^%theBase%^%thePostfix%%

After catching a couple of left out %'s in my in initial attempt - sure
enough two info boxes get displayed :-)

--
Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)

[Non-text portions of this message have been removed]
• Don, Thanks, I figured that I should be able to build the variable name but I did not include the leading ^ before %count% Vance
Message 4 of 5 , Jul 25, 2009
Don,

Thanks, I figured that I should be able to build the variable name but I
did not include the leading ^ before %count%

Vance

Don - HtmlFixIt.com wrote:
> You just use numbers.
>
> An array of 256 items has 257 elements, the first being the number of
> elements ...
>
> so ...
>
> ^!Info ^%MyArray% would show all 256 elements with the delimiter between
> them ....
> and
> ^!Info ^%MyArray0% would show the number of elements, in this case 256.
>
> Then
> ^!Info ^%MyArray1% would show the first element,
> ^!Info ^%MyArray2% wold show the second and so forth,
>
> so using a clip like this:
> ^!Set %count%="0"
> ^!Info Number of Elements: ^%MyArray^%count%%
> :Loop
> ^!Info Element Number ^%count% is: ^%MyArray^%count%%
> ^!Inc %count%
> ^!If "^%count%" > "^%MyArray0%" End ELSE Loop
>
> You should be able to show all elements and then each element ...
> Caveat: not tested, wrote it by hand ....
>
> Vance E. Neff wrote:
>> Hi,
>>
>> I have an array, %MyArray% that contains 256 elements.
>> If %ElementNum% contains the element # (1-256) that I want, how do I get
>> that element out of the array. I can't seem to locate the function to
>> do this.
>>
>> Vance
>>
>>
>>
>> ------------------------------------
>>
>> Fookes Software: http://www.fookes.com/
>> NoteTab website: http://www.notetab.com/
>> NoteTab Discussion Lists: http://www.notetab.com/groups.php
>>
>> ***
>>
>>
>>
>>
>
>
>
> ------------------------------------
>
> Fookes Software: http://www.fookes.com/
> NoteTab website: http://www.notetab.com/
> NoteTab Discussion Lists: http://www.notetab.com/groups.php
>
> ***
>
>
>
>
>
• Pretty common occurrence to forget the leading ^ in my world. And then of course it doesn t work as expected. And then a long time later you realize and
Message 5 of 5 , Jul 25, 2009
Pretty common occurrence to forget the leading ^ in my world. And then
of course it doesn't work as expected. And then a long time later you
realize and think ... oh yeah.

Vance E. Neff wrote:
> Don,
>
> Thanks, I figured that I should be able to build the variable name but I
> did not include the leading ^ before %count%
>
> Vance
Your message has been successfully submitted and would be delivered to recipients shortly.