|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ASA. - Associative Array > Assoc. Array Management > ASA. - Associative Array Operations |
SPR Script Language
ASA.Validate
Checks if an associative array handle is valid.
Intention
The ASA.Validate command is like a safety check for your associative arrays in SPR. It takes a handle (stored in a variable like $$TRE) and tells you if it’s still good to use. When you make an array with ASA.New, the handle is valid. But after ASA.End or ASA.EndAll, it’s not. This command helps you avoid mistakes by confirming the handle works before you try commands like ASA.Set or ASA.Get. It’s super useful in big scripts where you might lose track of which arrays are still around.
Imagine you’ve got a phonebook array with a handle $$TRE. You’re not sure if it’s still active or if you accidentally deleted it with ASA.End. Running ASA.Validate gives you a quick answer: a number (not zero) if it’s good, or zero if it’s gone. Or maybe your robot script has lots of arrays for settings—use this to check before updating them. It’s a fast way to keep your script safe and running smoothly!
Illustration
✅ Handle Check: Test $$TRE for an array with "Name" → "Alice" to see if it’s still valid.
📋 Result: ASA.Validate puts a number in $$RES—non-zero means yes, zero means no!
Syntax
ASA.Validate|$$TRE[|$$RES]
Parameter Explanation
P1 - $$TRE - (Variable, 5 characters max)
This is the handle you want to check. It’s a 5-character variable (like $$TRE or $$ARR) that came from ASA.New. The command tests if this handle still points to a real array.
P2 - $$RES - (Optional, Variable, 5 characters max)
This is where SPR puts the answer. It’s an optional 5-character variable (like $$RES). If the handle is valid, you get a non-zero number (usually a positive integer). If it’s invalid (e.g., after ASA.End), you get zero. Skip this if you don’t need the result.
Examples
'***********************************
' ASA.Validate - Sample 1: Check a New Array
'***********************************
ASA.New|$$TRE|s
ASA.Validate|$$TRE|$$RES
MBX.Text|Handle $$TRE is valid: $$RES (should be non-zero)
ASA.End|$$TRE
MBX.Ready
'
'***********************************
' ASA.Validate - Sample 2: Check After End
'***********************************
ASA.New|$$TRE|i
ASA.End|$$TRE
ASA.Validate|$$TRE|$$RES
PRT.Hello, handle $$TRE validity: $$RES (should be 0)
MBX.Ready
'
'***********************************
' ASA.Validate - Sample 3: Check After EndAll
'***********************************
ASA.New|$$TR1|f
ASA.New|$$TR2|s
ASA.EndAll
ASA.Validate|$$TR1|$$RS1
ASA.Validate|$$TR2|$$RS2
PRT.Handle $$TR1 valid? $$RS1 (should be 0)
PRT.Handle $$TR2 valid? $$RS2 (should be 0)
MBX.Ready
'
Remarks
- Use $$RES to see the result: non-zero means $$TRE is ready for action, zero means it’s dead.
- This is great before risky operations—check $$TRE first to avoid errors with ASA.Set or ASA.Get.
- It’s fast and doesn’t change the array—just looks at it.
- Works the same no matter the datatype (String, Quad, Extended) set by ASA.New.
Limitations
- $$TRE must be 5 characters—wrong lengths might confuse SPR.
- If you don’t use $$RES, you won’t know the result unless you test the handle another way.
- Only checks the handle, not the data inside the array.
See also:
• ASA.New
• ASA.End
• ASA.Set