Array Variables in Mini Mouse Macro: A Comprehensive Guide
Table of Contents
Introduction
Arrays in Mini Mouse Macro provide a way to store and manage collections of data under a single variable name. They are essential for handling lists, sets, or any sequence of items, offering powerful capabilities for iterating, sorting, and manipulating data within your macros. This guide will explore array variables in detail, demonstrating their definition, usage, and practical examples, including advanced operations like reversing, sorting, and clearing arrays.
Defining Array Variables
Array variables in Mini Mouse Macro are defined using the DEFINE ARRAY VARIABLE
action. Each element in an array is essentially a separate variable, grouped under a common array name. You can use the internal %ARRAY%
name or define custom names for your arrays to improve readability.
Definition Examples
Defining an Array with the Default Name
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %ARRAY%::apple
2 | RUN ACTION | DEFINE ARRAY VARIABLE | %ARRAY%::banana
3 | RUN ACTION | DEFINE ARRAY VARIABLE | %ARRAY%::cherry
This code defines an array named %ARRAY%
and adds three elements to it: “apple”, “banana”, and “cherry”.
Defining an Array with a Custom Name
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%::apple
2 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%::banana
3 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%::cherry
Here, we define an array named %Fruits%
and add the same three elements. Using a custom name like %Fruits%
makes the purpose of the array clear.
Array Operations
Mini Mouse Macro provides several operations for manipulating arrays, including reversing, sorting, clearing, and iterating through elements.
Reversing an Array
The reverse
operation reverses the order of elements in an array.
Example: Reversing the %Fruits%
Array
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%.reverse
After this operation, the order of elements in the %Fruits%
array will be “cherry”, “banana”, “apple”.
Sorting an Array
The sort
operation sorts the elements of an array in alphabetical order.
Example: Sorting the %Fruits%
Array
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%.sort
After this operation, the order of elements in the %Fruits%
array will be “apple”, “banana”, “cherry” (assuming it was in its original order).
Clearing an Array
The clear
operation removes all elements from an array.
Example: Clearing the %Fruits%
Array
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %Fruits%.clear
After this operation, the %Fruits%
array will be empty.
Iterating Through an Array
You can iterate through the elements of an array using a FOR EACH
loop.
Example: Iterating Through the %Fruits%
Array
1 | FOR | EACH | FRUIT IN | %Fruits% | NEXT
2 | RUN ACTION | MESSAGE PROMPT | Fruit: %FRUIT%
3 | FOR | NEXT
This code will display a message prompt for each element in the %Fruits%
array. The %FRUIT%
variable will hold the value of the current element in each iteration.
Example: Iterating Through an Array with Index
14 | FOR | EACH | I IN | %ARRAY% | next
15 | RUN ACTION | MESSAGE PROMPT | %ARRAY%I%%::%i%::1
16 | FOR | NEXT
This code will display a message prompt for each element in the %ARRAY%
array along with its index.
Clearing All Arrays
You can clear all internal array variables using the CLEAR ALL ARRAYS
debug action.
1 | RUN ACTION | DEBUG | CLEAR ALL ARRAYS
This action clears custom variables, array variables, and internal event log events.
Practical Examples
Example 1: Working with Arrays and Indentation
This macro demonstrates defining an array, reversing its order, and iterating through its elements.
* | ******** | DEFINE ARRAY* | *******
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %COLORS%::red
2 | RUN ACTION | DEFINE ARRAY VARIABLE | %COLORS%::green
3 | RUN ACTION | DEFINE ARRAY VARIABLE | %COLORS%::blue
* | ******** | REVERSE ARRAY* | *******
4 | RUN ACTION | DEFINE ARRAY VARIABLE | %COLORS%.reverse
5 | RUN ACTION | MESSAGE PROMPT | Reversed Array::%COLORS%::1
* | ******** | ITERATE ARRAY* | *******
6 | FOR | EACH | COLOR IN | %COLORS% | NEXT
7 | RUN ACTION | MESSAGE PROMPT | Color: %COLOR%::::1
8 | FOR | NEXT
Detailed Explanation:
- Lines 1-3: Defines an array
%COLORS%
with elements “red”, “green”, and “blue”. - Lines 4-5: Reverses the array and displays the reversed contents.
- Lines 6-8: Iterates through each element and displays each color.
Example 2: Array Sorting and Clearing
This macro demonstrates sorting an array alphabetically and clearing its contents.
* | ******** | DEFINE AND SORT ARRAY* | *******
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %NAMES%::Zebra
2 | RUN ACTION | DEFINE ARRAY VARIABLE | %NAMES%::Apple
3 | RUN ACTION | DEFINE ARRAY VARIABLE | %NAMES%::Monkey
4 | RUN ACTION | DEFINE ARRAY VARIABLE | %NAMES%.sort
5 | RUN ACTION | MESSAGE PROMPT | Sorted Names::%NAMES%::1
* | ******** | CLEAR ARRAY* | *******
6 | RUN ACTION | DEFINE ARRAY VARIABLE | %NAMES%.clear
7 | RUN ACTION | MESSAGE PROMPT | Array Cleared!::Done::1
Detailed Explanation:
- Lines 1-3: Defines an array
%NAMES%
with elements “Zebra”, “Apple”, and “Monkey”. - Line 4: Sorts the array alphabetically.
- Line 5: Displays the sorted array.
- Lines 6-7: Clears the array and displays a confirmation message.
Example 3: Combining Labels, Comments, and Iteration
This macro defines an array of numbers, iterates through them, doubles each value, and displays the result.
* | ******** | DEFINE NUMBERS ARRAY* | *******
1 | RUN ACTION | DEFINE ARRAY VARIABLE | %NUMBERS%::1
2 | RUN ACTION | DEFINE ARRAY VARIABLE | %NUMBERS%::2
3 | RUN ACTION | DEFINE ARRAY VARIABLE | %NUMBERS%::3
* | ******** | DOUBLE EACH NUMBER* | *******
4 | FOR | EACH | NUMBER IN | %NUMBERS% | NEXT
5 | RUN ACTION | DEFINE INTEGER VARIABLE | %NUMBER%::*2
6 | RUN ACTION | MESSAGE PROMPT | Doubled Value: %NUMBER%
7 | FOR | NEXT
* | ******** | END* | *******
8 | RUN ACTION | MESSAGE PROMPT | All Values Doubled::Done::1
Detailed Explanation:
- Lines 1-3: Defines an array
%NUMBERS%
with elements 1, 2, and 3. - Lines 4-7: Iterates through each number, doubles it, and displays the result.
- Line 8: Displays a final confirmation message.
Visual Example: Array Operations in Action
The following image demonstrates the execution of a macro that defines, reverses, sorts, and iterates through an array, showcasing the event log in Mini Mouse Macro:
Further Exploration
This guide has covered the essentials of array variables in Mini Mouse Macro. To further enhance your skills, consider exploring the following topics:
- Decimal Variables: Learn about decimal variables for working with floating-point numbers.
- String Variables: Explore string variables for handling text and character data.
- Boolean Variables: Discover boolean variables for logical conditions and flow control.
- Pixel Variables: Dive into pixel variables for screen-based evaluations and interactions.
- Internal Variables: Explore predefined internal variables for dynamic content and system information.
- Control Flow: Dive deeper into control flow statements, such as
IF
,ELSE
, andGOTO
, to create more complex logic. - Advanced Actions: Investigate advanced actions, such as file operations, system commands, and external program execution.
- Community Forums: Engage with the Mini Mouse Macro community to share knowledge, ask questions, and learn from others.
By continuing to learn and experiment, you can master Mini Mouse Macro and create powerful automations to streamline your tasks and boost your productivity.