|
<< 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.Prev
Returns the handle to the previous node in an associative array.
Intention
The ASA.Prev command moves you backward through an associative array in SPR. You start with a node handle (like $$NODE from ASA.Last), and it gives you the handle to the previous node in $$PREVNODE. Each node is a key-value pair, and this lets you step back through them one by one. Use it with ASA.GetKey and ASA.GetVal to check each entry. It’s your tool for looping backward through the array, starting from ASA.Last until you reach the start.
Picture a phonebook array—start at "Zoe" with ASA.Last, then use ASA.Prev to move to "Yvonne". Keep going to list contacts in reverse. Or in a robot script with settings like "Speed" → "3.14", it steps you back from the last reading to earlier ones. It’s a quick, easy way to walk through your data in reverse order, great for tasks like reviewing entries from newest to oldest.
Illustration
⬅️ Step Back: From a node with $$NODE (like "Age" → "25"), ASA.Prev takes you to the previous pair, maybe "Name" → "Alice".
🔗 Prev Node: $$PREVNODE gets the handle to keep moving back through the array!
Syntax
ASA.Prev|$$TRE|$$NOD[|$$PRV]
Parameter Explanation
P1 - $$NODE - (Variable, 5 characters max)
This is the current node handle you’re at. It’s a 5-character variable (like $$NODE) from ASA.Last, ASA.First, or a previous ASA.Prev or ASA.Next. The command uses this to find the previous node.
P2 - $$PREVNODE - (Optional, Variable, 5 characters max)
This is where the previous node handle goes. It’s an optional 5-character variable (like $$PREVNODE). SPR puts a non-zero number here if there’s a previous node, or 0 if you’re at the start. Use this with ASA.GetKey or ASA.GetVal to see what’s there.
Examples
'***********************************
' ASA.Prev - Sample 1: Move to Previous in a String Array
'***********************************
ASA.New|$$TRE|s
ASA.Set|$$TRE|Alice|123-4567
ASA.Set|$$TRE|Bob|987-6543
ASA.Last|$$TRE|$$NOD
ASA.Prev|$$NOD|$$PRV
ASA.GetKey|$$PRV|$$KEY
MBX.Previous key is $$KEY (might be Alice)
MBX.Ready
'
'***********************************
' ASA.Prev - Sample 2: Prev at Start of a Quad Array
'***********************************
ASA.New|$$TRE|i
ASA.Set|$$TRE|Red|50
ASA.Set|$$TRE|Blue|75
ASA.First|$$TRE|$$NOD
ASA.Prev|$$TRE|$$NOD|$$PRV
PRT.Prev handle at start: $$PRV (should be 0)
MBX.Ready
'
'***********************************
' ASA.Prev - Sample 3: Step Back in an Extended FP Array
'***********************************
ASA.New|$$TRE|f
ASA.Set|$$TRE|Temp|23.5
ASA.Set|$$TRE|Speed|3.14
ASA.Last|$$TRE|$$NOD
ASA.Prev|$$TRE|$$NOD|$$PRV
ASA.GetVal|$$TRE|$$PRV|$$VAL
PRT.Previous value is $$VAL (might be 23.5)
MBX.Ready
'
Remarks
- $$NODE must be a valid node handle from ASA.Last, ASA.First, or a prior ASA.Prev or ASA.Next.
- If you’re at the first node, $$PREVNODE gets 0—no more nodes before it.
- The order follows SPR’s internal sorting—often alphabetical by key, but not guaranteed.
- Use with ASA.Last to loop backward, or pair with ASA.Next for two-way navigation.
Limitations
- $$NODE must be 5 characters—wrong lengths might cause problems.
- If $$NODE isn’t valid, $$PREVNODE might get junk—no error shown.
- Only gives the previous node handle—use other commands for the key or value.
See also:
• ASA.Last
• ASA.Next