|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ASA. - Associative Array > Assoc. Array Operation > ASA. - Associative Array Operations |
SPR Script Language
ASA.Next
Returns the handle to the next node in an associative array.
Intention
The ASA.Next command moves you forward through an associative array in SPR. You start with a node handle (like $$NODE from ASA.First), and it gives you the handle to the next node in $$NEXTNODE. Each node is a key-value pair, and this lets you step through them one by one. Use it with ASA.GetKey and ASA.GetVal to see what’s in each spot. It’s your tool for looping forward through the whole array, starting from ASA.First until you hit the end.
Imagine a phonebook array—start at "Alice" with ASA.First, then use ASA.Next to move to "Bob". You can keep going to list every contact. Or in a robot script with settings like "Temp" → "23.5", it steps you from one reading to the next. It’s a simple, fast way to walk through your data in order, perfect for tasks like printing everything out or checking each entry.
Illustration
➡️ Step Forward: From a node with $$NODE (like "Name" → "Alice"), ASA.Next takes you to the next pair, maybe "Age" → "25".
🔗 Next Node: $$NEXTNODE gets the handle to keep going through the array!
Syntax
ASA.Next|$$TRE|$$NOD[|$$NXT]
Parameter Explanation
P1 - $$TRE - (Variable, 5 characters max)
This is the handle of the array you’re checking. It’s a 5-character variable (like $$TRE or $$ARR) from ASA.New. The command uses this to find the last node.
P2 - $$NODE - (Variable, 5 characters max)
This is the current node handle you’re at. It’s a 5-character variable (like $$NODE) from ASA.First, ASA.Last, or a previous ASA.Next. The command uses this to find the next node.
P3 - $$NEXTNODE - (Optional, Variable, 5 characters max)
This is where the next node handle goes. It’s an optional 5-character variable (like $$NEXTNODE). SPR puts a non-zero number here if there’s a next node, or 0 if you’re at the end. Use this with ASA.GetKey or ASA.GetVal to see what’s there.
Examples
'***********************************
' ASA.Next - Sample 1: Move to Next in a String Array
'***********************************
ASA.New|$$TRE|s
ASA.Set|$$TRE|Alice|123-4567
ASA.Set|$$TRE|Bob|987-6543
ASA.First|$$TRE|$$NOD
ASA.Next|$$TRE|$$NOD|$$NXT
ASA.GetKey|$$TRE|$$NXT|$$KEY
MBX.Second key is $$KEY (might be Bob)
MBX.Ready
'
'***********************************
' ASA.Next - Sample 2: Next at End of a Quad Array
'***********************************
ASA.New|$$TRE|i
ASA.Set|$$TRE|Red|50
ASA.Last|$$TRE|$$NOD
ASA.Next|$$TRE|$$NOD|$$NXT
PRT.Next handle at end: $$NXT (should be 0)
MBX.Ready
'
'***********************************
' ASA.Next - Sample 3: Step Through an Extended FP Array
'***********************************
ASA.New|$$TRE|f
ASA.Set|$$TRE|Temp|23.5
ASA.Set|$$TRE|Speed|3.14
ASA.First|$$TRE|$$NOD
ASA.Next|$$$TRE|$$NOD|$$NXT
ASA.GetVal|$$TRE|$$NXT|$$VAL
PRT.Second value is $$VAL (might be 3.14)
MBX.Ready
'
Remarks
- $$NODE must be a valid node handle from ASA.First, ASA.Last, or a prior ASA.Next.
- If you’re at the last node, $$NEXTNODE gets 0—no more nodes ahead.
- The order follows SPR’s internal sorting—often alphabetical by key, but not always predictable.
- Use with ASA.First to loop forward, or pair with ASA.Prev for two-way navigation.
Limitations
- $$NODE must be 5 characters—wrong lengths might break it.
- If $$NODE isn’t valid, $$NEXTNODE might get junk—no error shown.
- Only gives the next node handle—use other commands for the key or value.
See also:
• ASA.Prev