Jump to content
Macro Express Forums

Collecting data in arrays, or in separate variables


Recommended Posts

I would be curious to learn how other Macro Express users would handle this situation.

The task is to copy data from several fields, and insert the data into corresponding fields in another application, but in a different order.

12 pieces of information need to be copied.

Here are the two approaches.

1. Collect the data in an array

%Value[1]%
%Value[2]%
%Value[3]%
...
%Value[12]%

After collecting the data, the macro switches to the second application, and inserts the text into fields, but in a different order:

%Value[2]%
%Value[3]%
%Value[6]%
etc.

2. Use descriptive variable names

%Honorific%
%FirstName%
%SurName%
%Address1%
%Address2%
etc.

It seems to me that collecting data in an array is probably the more elegant and efficient way to get the job done.

On the other hand, using descriptive variable names make it clearer what the macro is doing, and make it easier to match up corresponding fields in the two applications.

Which approach would you use?

Link to comment
Share on other sites

I'm a fan of arrays but in this case I would want my variables to represent the type of thing it will hold. It helps make your code more readable which can grant huge dividends later. I knwo when I revisit code a year later it takes me time to reacquaint myself. But if these came in and an array were generated as the result of a split, I'd tend to leave the array of strings as is for performance. IE it seems silly to copy all these array variables to new named variables. 

BTW I often have multiple arrays that virtually form a Db table by using the index number as a quasi-row-number. So in your example above I'd have like in your second example but they would be arrays and each index would represent another individual's variables. 

My final word is that in most cases performance is not an issue. In those cases, do whatever you can to make it simpler and easier to understand after you have been away form it for a time. I try to write my macros as if I was handing it off to someone else to maintain. Many times I've been very happy I did. 

Link to comment
Share on other sites

1 hour ago, Cory said:

in most cases performance is not an issue. In those cases, do whatever you can to make it simpler and easier to understand after you have been away form it for a time. I try to write my macros as if I was handing it off to someone else to maintain. Many times I've been very happy I did. 

I agree 100% -- said he who still mostly uses ME3🙂.

Link to comment
Share on other sites

Thanks for your input. I agree.

 

However, if there were many more data points to collect -- say 100 instead of 12 -- I might be tempted to use arrays, but to write a bunch of comments to guide future maintenance, e.g.,

// Text Variable %Value[1 to 100]%
// [1] = Honorific
// [2] = First name
// [3] = Last name
...
// [100] = Date of last update

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...
×
×
  • Create New...