Hash tables and dictionaries

Previous topic - Next topic

AndyH

Has anyone here created code for a nice Hash table or Dictionary they would be able to share?  You know the key - value type of object.

Ian Price

I did for PlayBasic ages ago, I presume the values are the same...

May not be exactly what you are looking for -

Code (glbasic) Select
Dim key$(250)

key$(1)="ESC"
key$(2)="1"
key$(3)="2"
key$(4)="3"
key$(5)="4"
key$(6)="5"
key$(7)="6"
key$(8)="7"
key$(9)="8"
key$(10)="9"
key$(11)="0"
key$(12)="-"
key$(13)="="
key$(14)="BACKSPACE"
key$(15)="TAB"
key$(16)="Q"
key$(17)="W"
key$(18)="E"
key$(19)="R"
key$(20)="T"
key$(21)="Y"
key$(22)="U"
key$(23)="I"
key$(24)="O"
key$(25)="P"
key$(26)="["
key$(27)="]"
key$(28)="ENTER"
key$(29)="LEFT CTRL"
key$(30)="A"
key$(31)="S"
key$(32)="D"
key$(33)="F"
key$(34)="G"
key$(35)="H"
key$(36)="J"
key$(37)="K"
key$(38)="L"
key$(39)=";"
key$(40)="'"
key$(41)="`"
key$(42)="LEFT SHIFT"
key$(43)="#"
key$(44)="Z"
key$(45)="X"
key$(46)="C"
key$(47)="V"
key$(48)="B"
key$(49)="N"
key$(50)="M"
key$(51)=","
key$(52)="."
key$(53)="/"
key$(54)="RIGHT SHIFT"
key$(55)="* NUMPAD"
key$(56)="ALT"
key$(57)="SPACE"
key$(58)="CAPS"
key$(59)="F1"
key$(60)="F2"
key$(61)="F3"
key$(62)="F4"
key$(63)="F5"
key$(64)="F6"
key$(65)="F7"
key$(66)="F8"
key$(67)="F9"
key$(68)="F10"
key$(69)="NUM LOCK NUMPAD"
key$(70)="SCROLL LOCK"
key$(181)="/ NUMPAD"
key$(71)="7 NUMPAD"
key$(72)="8 NUMPAD"
key$(73)="9 NUMPAD"
key$(74)="- NUMPAD"
key$(75)="4 NUMPAD"
key$(76)="5 NUMPAD"
key$(77)="6 NUMPAD"
key$(78)="+ NUMPAD"
key$(79)="1 NUMPAD"
key$(80)="2 NUMPAD"
key$(81)="3 NUMPAD"
key$(82)="0 NUMPAD"
key$(83)="DEL NUMPAD"
key$(86)="\"
key$(87)="F11"
key$(88)="F12"
key$(156)="ENTER NUMPAD"
key$(157)="RIGHT CTRL"
key$(183)="PRINT SCREEN"
key$(184)="ALT GR"
key$(197)="PAUSE BREAK"
key$(199)="HOME"
key$(200)="CURSOR UP"
key$(201)="PAGE UP"
key$(203)="CURSOR LEFT"
key$(205)="CURSOR RIGHT"
key$(208)="CURSOR DOWN"
key$(210)="INSERT"
key$(211)="DELETE"
key$(207)="END"
key$(209)="PAGE DOWN"
key$(210)=" "
key$(211)="?"
Doesn't appear to be the full list of keys and as KEY is a keyword in GLB, you might have to rename key$. I have not tried this in GLB.
I came. I saw. I played.

AndyH

Thanks Ian - I'll keep that - will come in useful.  However I'm meaning a key-value pair in a VB dictionary or hash table, or associated array.  like:

key,  value
"Name", "Andy"
"Age", "10000"
"Key 5", "Active"


The key's and values can be anything, as that is not important, but you can look up the "key" eg "Name" to get the value "Andy" rather than using array element numbers.  Here's an example of what I mean.

bigsofty

Here's a VB Basic simple example. Looks very simple to convert to GLB. I'd do it myself but Im away from home today.

Hope it helps...

http://www.freevbcode.com/ShowCode.asp?ID=8581

Oops, sry, forgot the URL! :P
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)