Jump to content
Macro Express Forums
Snyder7

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!

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×