Jump to content
Macro Express Forums

Load non-sequential values into an array


Recommended Posts

I need to create an array with the following values:

1 0.6
2 1.5
3 2.5
4 3.5
5 4.5
6 5.5
7 6.5
8 7.5
9 8.5
10 9.5
11 10.5
12 11.5
13 12.5
14 13.5
15 14.5
16 16
17 18.5
18 22.5
19 27.5
20 32.5
21 40
22 63.5

So, when I increment through the array, it would return the values. For example %test[3]% = 2.5

How can I load these values into the array without having to manually enter a modify variable for each value?

Mark

 

Link to comment
Share on other sites

 

Hi Mark,

Hope the screenshot, annotated command text and command code will show you one way of doing it.

I've used commas to separate the nunbers, but any other sensible character would be OK too.

If you were doing this with many different sets of numbers, with varying numbers of elements, then a more flexible approach would be to set up text files first. But the crucial part is the indexing, as illustrated.

 

Variable Set String %tNumbers% to "0.6,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,16,18.5,22.5,27.5,32.5,40,63.5"
Split String "%tNumbers%" on "," into %tArray22%, starting at 1
// Then continue with your macro. Here I've simply displayed each of the 22 elements in the array.
Repeat Start (Repeat 22 times)
  Text Box Display: Result
End Repeat

 

<VARIABLE SET STRING Option="\x00" Destination="%tNumbers%" Value="0.6,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,16,18.5,22.5,27.5,32.5,40,63.5" NoEmbeddedVars="FALSE"/>
<SPLIT STRING Source="%tNumbers%" SplitChar="," Dest="%tArray22%" Index="1"/>
<COMMENT Value="Then continue with your macro. Here I've simply displayed each of the 22 elements in the array."/>
<REPEAT START Start="1" Step="1" Count="22" Save="TRUE" Variable="%nCount%"/>
<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 tArray22[%nCount%] = %tArray22[%nCount%]%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="425" Width="278" Height="258" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<END REPEAT/>

 

IndexAnArray.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...