Dictionaries are special data types that store pairs of some values.
Each pair consist of Key and Value.
Basic ways how to work with Dictionaries are covered in our RPA Foundation course.
So let’s do just a quick recap.
You can download example file for this article here: SortDictionary.zip (36.5 KB)
Create a variable and Browse for types, look for:
Pick your desired data type of key and value.
Initialize default value of empty dictionary with:
New Dictionary(Of String, Int32)
Add items using Assign activity. Write key on the left side and value on the right side as this:
- key = Isaac Asimov
- value = 1920
You can create a new, sorted Dictionary from an unsorted one using this VisualBasic .NET method within the Assign activity.
unsorted_dictionary.OrderBy(function(x) x.Value).ToDictionary(function(y) y.Key,function(y) y.Value)
In our example, ( SortDictionary.zip (36.5 KB) ) you can see both ways to sort: by key and also by value.
If you would like to sort in descending order, change the method from OrderBy → OrderByDescending