Hash Sort

Purpose

Sorts a hash table by its keys.

Syntax

Hash Sort name[] [Asc | Desc] [, compmode]

Description

Hash Sort sorts a hash table in ascending Asc or descending Desc order. The ascending order is the default.

By default, the sort is performed according to the current Mode Compare setting. However, it is possible to force the command to sort according to a different mode by specifying the numerical (not string) value of this mode in the compmode parameter; the possible values for compmode are the same as for Mode Compare.

Example

Dim ha As Hash Variant, v As Variant

ha["new"] = 2.3

ha["Old"] = 2

// ascending

Hash Sort ha[]

Hash_Print("Ascending order")

// descending

Hash Sort ha [] Desc

Hash_Print("Descending order")

// ascending, sorted by using uppercase conversion

Hash Sort ha [] Asc , -1

Hash_Print("Ascending order using Uppercase Conversion")

// or (does the same)

Hash Sort ha [] , -1

Hash_Print("...and the same again")

 

Sub Hash_Print(t$)

Print t$ : Print

For Each v In ha[]

Print ha[$ Each], v

Next

Print

EndSub

Remarks

The hash table isn't sorted by the values of the elements like an array, but by its keys!

See Hash for more information on the Hash table.

See Also

Hash Add, Hash Erase, Hash Input, Hash Load, Hash Remove, Hash Save, Hash Write

{Created by Sjouke Hamstra; Last updated: 26/07/2020 by James Gaite}