SetMap/GetMap with numeric (Hex) keys
Posted: Wed Aug 31, 2011 10:24 am
Code: Select all
EnableExplicit
;
Structure TestStruc
X.D
Y.D
Z.D
EndStructure
;
NewMap Mp1.TestStruc()
NewMap Mp2.String()
; *************************************************************
;MP is a Structured Map()
;Key is any long or int. (Converted to hex by the macro)
;Field is the literal field of the structure
; *************************************************************
Macro SetMap(Mp,Key,Field,Va)
;Set key value VA on field Field on map MP
;Va must be of the PB Type corresponding to the Map structure
MP(Hex(Key))\Field = Va
EndMacro
;
; Get Key value from field Field on map MP
Macro GetMap(MP,Key,Field)
Mp(Hex(Key))\Field
EndMacro
;
; out: String from GetMap - (only to save some keystrokes)
Macro MapS(MP,Key,Field)
StrD(GetMap(Mp,Key,Field))
EndMacro
;
;test it <<<<<<<<<<<<<<<<<<<<<<<<<<
Define X.D=#PI
;Here x is two different things:
SetMap(Mp1,1,X,X) ;) first x is the TestStruc "x" field; second x is #pi
SetMap(Mp1,2,Y,#PI*10) ; second param is a numeric key
SetMap(Mp1,3,Z,#PI/10)
SetMap(Mp2,1,S,StrD(#PI*#PI))
;
Define T$="X="+ Maps(Mp1,1, X)+#CRLF$
T$+"Y="+ Maps(Mp1,2, Y)+#CRLF$ ;or call GetMap(Mp1,2,y) te get the numeric value
T$+"Z="+ Maps(Mp1,3, Z)+#CRLF$
T$+"_____________"+#CRLF$
T$+"Mp2="+GetMap(Mp2,1,S)
;
MessageRequester("Test",T$,0)