|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > !Collections/Fast Arrays > Fast Array-Commands > Smart Package Robot 's Collection Commands |
MiniRobotLanguage (MRL)
AFV.-Command
Array From Variable
Intention
AFV. stands for "Array From Variable". It populates an Array from a Variable that was filled using CTV.
AFV. performs the inverse operation of CTV., creating or restoring a Array from the string content of a variable.
This command is pivotal for reconstructing Arrays from saved data.
This command can also be used to import a CSV file, or Comma Separated Value file, into a collection.
You simply need to specify the appropriate delimiter used in the CSV file as P3.
This allows you to directly import a CSV file into the collection.
Please note the important distinction:
AFV. - import any Elements without checking for duplicates
CFV. - import no duplicate Elements each Element is only one time in the Collection
Both commands are complementary to CTV.
Unlike arrays, a collection can only contain a single instance of a specific element. This means no duplicates or repeated elements are added to the collection.
This is the only difference.
Please read the general information about Collections and Fast Arrays.
Important:
For technical and speed reasons, there is no verification to check if a valid delimiter has been provided that actually works for the P2 string.
If the required delimiter is not specified or an incorrect delimiter is given, it may cause the script to terminate due to a memory error.
However, it is recommended to use the same delimiter as in the complementary command "Collection To-Variable" CTV..
Syntax
AFV.P1|P2[|P3]
Parameter Explanation
P1 - The Array identifier, typically a numeric value or a variable that contains a number from 0 to 1024/1025 to 2048.
P2 - The variable containing the string to be moved into the collection. This variable must have been created using CTV.
P3 - (optional) Delimiter (character or string), if omitted, "Binary" is used, only in the "Binary-Mode" you can add all sorts of Elements, otherwise the Elements can never contain the delimiter-character.
Example
'***************************************************************
' Testing Script for CTV., AFV., JIU., and JNU. Commands
'***************************************************************
' Initialize collection 0 and ensure it's empty
VAR.$$C00=0
CLC.$$C00
DBP.Initializing and clearing collection 0.
' Add unique elements to the collection
VAR.$$N10=John
ATC.$$C00|$$N10
VAR.$$N11=Jane
ATC.$$C00|$$N11
VAR.$$N12=Mike
ATC.$$C00|$$N12
DBP.Added John, Jane, and Mike to collection 0.
' Transfer the content of collection 0 to variable $$DAT
CTV.$$C00|$$DAT
DBP.Transferred collection 0 to variable $$DAT.
' Clear collection 0 again to demonstrate restoring
CLC.$$C00
DBP.Cleared collection 0 for restoration test.
' Restore collection 0 from variable $$DAT
AFV.$$C00|$$DAT
DBP.Restored collection 0 from variable $$DAT.
' Verify the restoration by checking each name's uniqueness, which now means checking if they are already in the collection
JIU.$$C00|$$N10|john_not_unique
DBP.John is not unique, as expected.
JMP.check_jane
:john_not_unique
DBP.Error: John is unexpectedly considered unique.
:check_jane
JIU.$$C00|$$N11|jane_not_unique
DBP.Jane is not unique, as expected.
JMP.check_mike
:jane_not_unique
DBP.Error: Jane is unexpectedly considered unique.
:check_mike
JIU.$$C00|$$N12|mike_not_unique
DBP.Mike is not unique, as expected.
JMP.end_verification
:mike_not_unique
DBP.Error: Mike is unexpectedly considered unique.
:end_verification
DBP.All elements verified to be in the collection correctly.
' End of script
ENR.

'***************************************************************
' Streamlined Testing Script for CTV., CFV., JIU., and JNU. Commands
'***************************************************************
' Initialize collection 0 and ensure it's empty
VAR.$$C00=0
CLC.$$C00
DBP.Initializing and clearing collection 0.
' Add unique elements to the collection
VAR.$$N10=John
ATC.$$C00|$$N10
DBP.Added John to collection 0.
VAR.$$N11=Jane
ATC.$$C00|$$N11
DBP.Added Jane to collection 0.
' Test with JIU. to jump if John is already in the collection (which he is)
JIU.$$C00|$$N10|john_is_in
DBP.John was not added again, proceeding with script.
JMP.verify_jane
:john_is_in
DBP.John is in the collection as expected.
:verify_jane
' Use JIU. to check if Jane is in the collection
JIU.$$C00|$$N11|jane_is_in
DBP.Jane was not added again, proceeding with script.
JMP.add_anna
:jane_is_in
DBP.Jane is in the collection as expected.
:add_anna
' Prepare a new unique element, Anna, not yet in the collection
VAR.$$N13=Anna
' Use JNU. to jump if Anna is not in the collection (she is not)
JNU.$$C00|$$N13|anna_not_in
DBP.Adding Anna to the collection since she is not present.
ATC.$$C00|$$N13
JMP.finish
:anna_not_in
DBP.Error: Anna unexpectedly considered in the collection.
:finish
' Transfer collection 0 to a variable and restore it to verify all elements
CTV.$$C00|$$DAT
CLC.$$C00
AFV.$$C00|$$DAT
DBP.Restored collection 0 from variable. Verifying contents...
' Verify Anna's presence using JIU. after restoration
JIU.$$C00|$$N13|anna_is_in
DBP.Verification failed: Anna should be in the collection.
JMP.end_script
:anna_is_in
DBP.Anna is verified to be in the collection post-restoration.
:end_script
DBP.All elements correctly verified. Test concluded.
' End of script
ENR.

Remarks
-
Limitations:
-
See also:
• CFV. - Collection from Variable
• CTV. - Collection to Variable
• RFC. - Remove from Collection