I frequently wish I could use QuickParams
to create a dictionary with more than three items.
This modification seems to work fine, but I notoriously overlook obvious issues.
Any comments or suggestions?
<function name="QuickParams" parameters="key1, value1, key2, value2, key3, value3" type="dictionary">
d = NewDictionary()
// stringlist block added by KV
if (TypeOf(key1) = "stringlist") {
for (i, 0, ListCount(key1), 2) {
if (not i = ListCount(key1)) {
dictionary add (d, StringListItem(key1,i), StringListItem(key1,i+1))
}
}
return (d)
}
// "fromstring:" block added by KV
if (TypeOf(key1) = "string" and StartsWith(key1, "fromstring:")){
key1arr = Split(Replace(key1, "fromstring:", ""), ",")
for (i, 0, ListCount(key1arr), 2) {
if (not i = ListCount(key1arr)) {
dictionary add (d, StringListItem(key1arr,i), StringListItem(key1arr,i+1))
}
}
return (d)
}
dictionary add (d, key1, value1)
if (IsDefined("key2")) {
dictionary add (d, key2, value2)
}
if (IsDefined("key3")) {
dictionary add (d, key3, value3)
}
return (d)
</function>
<start type="script">
msg (QuickParams ("one", "1", "two", "2", "three", "3"))
msg (QuickParams (Split("four,4,five,5,six,6,seven,7,eight,8", ",")))
msg (QuickParams ("fromstring:nine,9,ten,10,eleven,11,twelve,12,thirteen,13"))
</start>