Jump to content
Macro Express Forums

Arrays Explained?

Recommended Posts

Hey guys.

So, I'm having some difficulty understanding how arrays work within MEP; I understand the concept of an array in general but yesterday I spent quite a while trying to build a simple array to hold 108 integer variables (0-107) so I could start learning how to interact with them. However I kept getting various errors about the array itself not being defined with the correct type and it was crashing my MEP left and right. I was using a string to set all the numbers (separated by commas) and then a splitstring on the comma repeated into an %nCounter% variable within a repeat loop. I dug around on the forums for a while and found some useful help but I'm wondering if someone could break down the basic process of how arrays are defined and called in MEP. I know it's a general request but I think my problem is that I don't know how MEP looks at arrays in general.

Thanks as always!

Link to comment
Share on other sites

When you define an array variable you need to specify the number of elements. Sometimes that is tricky if you aren't sure how many you will need. I usually just guess high. So, for your array variable that needs 0-107 elements I would specify 150 or 200 elements.

Sometimes I use the Get Array Length command in my macros to check to display a warning if the array size is too small. That prompts me to edit the macro and increase the size of the array.

To access elements in the array use something like %ArrayVar[1]%,  %ArrayVar[99]%,  etc. You can also use another variable to access the array. %ArrayVar[%Idx%]%.

Also note that array variables start with 1, not 0. %ArrayVar[1]% is okay but %ArrayVar[0]% is not.

Link to comment
Share on other sites

Dear lord I can't believe I spent so long agonizing over my array not functioning only to realize I THOUGHT IT STARTED AT ZERO. Silly mistake...but after working on my macro for a while I've successfully figured out how to perform simple tasks using the data in the array; thank you for your response! To anyone else reading this feel free to ignore, I am comfortable with basic array functionality now. I'm sure I'll have more problems/questions as I continue but for now my macro is functioning appropriately. Thanks again!

Link to comment
Share on other sites

It wasn't a silly mistake. Every programming language I know of have zero-based arrays. I believe ISS did this because for non-programming types, the concept of zero based arrays is confusing. Also avoids "length minus one" for loops. 

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.

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.

  • Create New...