Saving to an array in a loop

Curious if it's possible to save to an array without initializing the array?

In "Event Speaker Variables (Working)" I tried to save into the 1st index of an empty variable, but this just leads to an empty variable.

In "Event Speaker Variables" I was able to get things working, but only by saving variables initially, then appending to those variables in a while loop.

Is there an elegant solution, or am I on the right path by appending into an array that I first initialize.

What I'm looking to do is create an array of first names, last names, email addresses, etc for our event speakers so that I can quickly register on behalf of them in Eventbrite. The # of speakers changes for each event, so I wanted to create a Macro that would ask for the # of speakers, create an array of their contact information, so that in another Macro I can loop pasting in all of those values.

MyDev Macros.kmmacros (14 KB)

Yes. But in the Set Variable to Text action you need to check the "Append to variable" option in the Gear menu:

I think there is a better solution, depending on how you need to paste the results into your web site.

IMO, it is generally better to create a tab-delimited (or comma-delimited) list that has one record on each line/row.

IAC, here is an example macro to help get you started.
It does the following:

  1. Builds a KM Global Variable of tab-delimited data like this:
    First Name\tLast Name\tCompany Name
  2. Allows you to start a new list, or append to an existing list
  3. Outputs to:
    • KM Display Text window
    • System Clipboard, ready to paste into Excel or other spreadsheet

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Changes You Need to Make

  1. Modify the Prompt for User Input to change/add the speaker data fields you want
  2. Make these same changes in the Actions below it

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example Output

image

image

image

The System Clipboard is also set to this same tab-delimited list, suitable for pasting into Excel or other spreadsheet.

MACRO:   Build Tab-Delimited List in a Loop [Example]

**Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/b/d/bdcff0c8f079163776d751fbe08ffb33177273ee.kmmacros">Build Tab-Delimited List in a Loop [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---

### ReleaseNotes

Author.@JMichaelTX

**PURPOSE:**

* **Build Tab-Delimited List in a Loop**

**NOTICE: This macro/script is just an _Example_**

* It is provided only for _educational purposes_, and may not be suitable for any specific purpose.
* It has had very limited testing.
* You need to test further before using in a production environment.
* It does not have extensive error checking/handling.
* It may not be complete.  It is provided as an example to show you one approach to solving a problem.

**REQUIRES:**

1. **KM 8.0.2+**
2. **macOS 10.11.6 (El Capitan)**

**MACRO SETUP**

* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.  šŸ˜‰
.
* Assign a Trigger to this maro.
* Move this macro to a Macro Group that is only Active when you need this Macro.
* ENABLE this Macro.
.
* **REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:**
  * ALL Actions that are shown in the magenta color

**USE AT YOUR OWN RISK**

* While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

<img src="/uploads/default/original/3X/8/0/8040ed0a7fce90d0b81e2447f987900024987597.png" width="530" height="1697">
1 Like

Thanks for all this. I definitely like the idea of having each record on a line. Iā€™m trying to prevent variable bloat as my use of KM increases. :grinning:

PS just subscribed to your YouTube channel.

1 Like