Here's an untested idea, but an approach I have used before.
Put your questions in a single KM variable (or a file), one question per line
Use a KM For Each action on a lines collection in that variable
Use a variable to track the count, and build the KM variable name for each answer dynamically (or append each answer to a single variable, one line per answer).
Then you just need one IF/THEN in the For Each loop to test for your condition.
Maybe in using the questions, but getting the questions into the Dictionary could be painful and verbose. Then, even more effort just to view/edit the questions. That's why I went with using a simple text file as the source for the questions. Easy to create and maintain.
That's valid. I guess, since I utilise dictionaries a lot, I've created a bunch of macros/AppleScripts to make creating, editing, viewing and deleting them easy/easier. I probably agree that your method is better for most people who haven't done this, but I don't think there's any harm in providing an alternative way of doing things.
This is easily done with the For Each action and the Lines In collection to iterate over the variable names, and the Filter action to get the “Value of Named Variable”. Something like this:
But I also want to address a question you did not ask: How Do I Create and Maintain the LIst of Questions.
As far as I can tell, all of the above solutions pretty much ignore this question.
So I have built a solution that uses a plain text file for both the Questions and the Answers.
This makes it easy to enter, review, edit, and maintain. I don't like using a lot of KM Variables or Dictionary Keys for lists of items. KM just does not provide the tools to make entry/edit of these easy.
And, with a text file you can easily share with others for their review/input.
So here's my macro:
Example of Question in File (show in BBEdit)
(Note I am showing the "invisibles" in BBEdit so you can see TABS, SPACES, and LF)
MACRO: Prompt for Answers to List of Questions [Example]
#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/c/d/cda41c61a635175454ac76a4c591deacb69f23c4.kmmacros">Prompt for Answers to List of Questions [Example].kmmacros</a> (14 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
### ReleaseNotes
Author.@JMichaelTX
**PURPOSE:**
* **Prompt for Answers to List of Questions**
* Both Questions and Answers may be stored in files.
**HOW TO USE**
1. First, make sure you have followed instructions in the _Macro Setup_ below.
2. Trigger this macro.
**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. ??
.
1. Assign a Trigger to this maro.
2. Move this macro to a Macro Group that is only Active when you need this Macro.
3. ENABLE this Macro.
4. Create plain text file of questions in the same format as the Set Variable to Local__QuestionsList below
* Then ENABLE these Actions:
* Set to File of Questions
* Set File for Answers
.
* **REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:**
(all shown in the magenta color)
* DISABLE List of Questions for TESTING
* OR, modify as you wish for testing.
**REQUIRES:**
1. **KM 8.2+**
2. **macOS 10.11.6 (El Capitan)**
TAGS: @Survey @Questions @RegEx
USER SETTINGS:
* Any Action in _magenta color_ is designed to be changed by end-user
ACTION COLOR CODES
* To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows:
* GREEN -- Key Comments designed to highlight main sections of macro
* MAGENTA -- Actions designed to be customized by user
* YELLOW -- Primary Actions (usually the main purpose of the macro)
* ORANGE -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions
**==USE AT YOUR OWN RISK==**
* While I have given this a modest amout of testing, and to the best of my knowledge 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.
---
![image|510x2000](upload://ds8S5VzoKywGm8wdaNgbqIHFH7A.png)
---
### Questions?