Smart Package Robot 's Collection Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > !Collections/Fast Arrays > Collection-Commands >

 Smart Package Robot 's Collection Commands

CFV. - Collection from Variable

Previous Top Next


MiniRobotLanguage (MRL)

 

CFV.-Command

Collection From Variable

 

 

Intention

 

CFV. stands for "Collection From Variable". It populates a collection from a Variable that was filled using CTV.

CFV. performs the inverse operation of CTV., creating or restoring a collection from the string content of a variable.

This command is pivotal for reconstructing collections 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 parameter 3 (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

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.

 

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

 

 

CFV.P1|P2[|P3]

 

 

 

Parameter Explanation

 

P1 - The collection 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.

 

*Collection Type 1: "Word-Collections".

They are numbered from 0 to 1024.

 

Collection Type 2: "Checksum-Collections".

They are numbered from 1025 to 2048.

 

 

Example

 

'***************************************************************

' 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

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

CFV.$$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.

 

clip1018

 


 

 

'***************************************************************

' 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

CFV.$$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.

 

 

clip1019

 

 

 

 

 

Remarks

 

-

 

 

Limitations:

-

 

 

See also:

 

ATC. - Add to Collection

CFV. - Collection from Variable

CGC. - Collection Get Count

CLC. - Clear Collection

CTV. - Collection to Variable

JIU. - Jump if Unique

JNU. - Jump Not Unique

RFC. - Remove from Collection