02-28-2023, 06:24 PM
(02-28-2023, 03:33 PM)Kernelpanic Wrote: There is a small error in the first code on the page. Thats how it works:
Code: (Select All)'Assosziatives Array: https://jeff.win/qbhash/
'28. Feb. 2023
Type element
tag As String * 10
value As String * 10
End Type
Dim Shared aa(10) As element
Dim Shared aalast ' Last occupied AA() element
setvalue "foo", "bar"
Print getvalue$("foo") ' prints bar
End
Function getvalue$ (tag As String)
tag = LTrim$(RTrim$(tag))
tag = tag + String$(10 - Len(tag), " ")
For i = 0 To aalast
If (tag = aa(i).tag) Then
getvalue$ = aa(i).value
Exit Function
End If
Next
End Function
Sub setvalue (tag As String, value As String)
aa(aalast).tag = tag
aa(aalast).value = value
aalast = aalast + 1
End Sub
One advantage of associative arrays didn't in moment become clear to me. Similar to a two-dimensional random access array. . . That's how I understood it.
Yes that can be quite useful in a lot of cases.
I haven't had a chance to test that code sample - is it broken?
Were you able to fix it?
I can give it a look later, and provide better examples that I did run and were working (at least they were a year or two ago, LoL!)