Class Map : A key (String) / value (Object) dictionary
File : util/Map.vbs
Unit test file : test/MapTest.vbs
Methods (key is string, value must be a object or struct) :
- index = putValue key, value
- set value = getValue(key)
- set value = removeValue(key)
- exists = isValueExist(key)
- index = getIndex(key)
- size = getSize()
faster methods by using index (so act also like a List):
- set value = getValueByIndex(index)
- set value = removeValueByIndex(index)
- replaceValueByIndex index, value
- key = getKeyByIndex(index)
Sample code (for a complete sample, see MapTest.vbs) :
Code:
ExecuteGlobal LoadExternalScript ("util\Map.vbs")
class struct
public text
end class
sub test()
dim objMap
dim tmp
dim i
set objMap = new Map
for i=0 to 2
set tmp=new struct
tmp.text="elem " & i
objMap.putValue "key"&i, tmp
next
AddDebugText "EXIST = " & objMap.isValueExist("key1")
end sub
Tips :
- Map must be reserved for complex needs, but are very powerfull. You can access it like a List when you have known indexes.