« on: April 05, 2021, 08:10:03 pm »
Hi guys and gals
going back to school I find a fine exercise
build a dictionary
here a dictionary using a string and delimiters, very simple.
'Demo area---------------->
If PutDict
(MyDictionary
, "a", "Ananas") Then Print "added new couple key value" If PutDict
(MyDictionary
, "b", "Banana") Then Print "added new couple key value" If PutDict
(MyDictionary
, "c", "cherry") Then Print "added new couple key value" If PutDict
(MyDictionary
, "d", "Drake") Then Print "added new couple key value" If PutDict
(MyDictionary
, "e", "Elm") Then Print "added new couple key value" If PutDict
(MyDictionary
, "f", "Fire") Then Print "added new couple key value"
Print "to key e there is "; GetDict$
(MyDictionary
, "e") Print "to key e there is "; GetDict$
(MyDictionary
, "a") If ChangeValue
(MyDictionary
, "e", "Elephant") Then Print " changed value of key passed" Print "to key e there is "; GetDict$
(MyDictionary
, "e") If Not (EraseKeyValue
(MyDictionary
, "e")) Then Print " Failed to erase key value passed" Else Print "Erased key value passed" If GetDict$
(MyDictionary
, "e") = "" Then Print " No couple key value found for key value 'e'" ' End demo area --------------->
PutDict = 0
dict = dict + Skey + keys + SValue + value + EValue
PutDict = -1
StartK
= InStr(dict
, Skey
+ Keys
+ SValue
) StartV
= InStr(StartK
, dict
, SValue
) EndV
= InStr(StartV
, dict
, EValue
) If StartK
= 0 Then GetDict$
= "" Else GetDict
= Mid$(dict
, StartV
+ 1, EndV
- StartV
)
ChangeValue = 0
StartK
= InStr(dict
, Skey
+ Keys
+ SValue
) StartV
= InStr(StartK
, dict
, SValue
) EndV
= InStr(StartV
, dict
, EValue
) StartK = PutDict(dict, Keys, NewValue)
dict
= Left$(dict
, StartV
) + NewValue
+ Right$(dict
, Len(dict
) - EndV
+ 1) ChangeValue = -1
EraseKeyValue = 0
StartK
= InStr(dict
, Skey
+ keys
+ SValue
) StartV
= InStr(StartK
, dict
, SValue
) EndV
= InStr(StartV
, dict
, EValue
) EraseKeyValue = -1
Play with it.
« Last Edit: April 11, 2021, 05:20:01 pm by TempodiBasic »
Logged
Programming isn't difficult, only it's consuming time and coffee