add MacroA Or MacroA()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

add MacroA Or MacroA()

Post by gurj »

add MacroA Or MacroA()
add MacroA:

Code: Select all

Dim u.s(7)
u(3)="kk"

MacroA var(Array, value)
Array=value
EndMacroA

var(u(3), 8)
Debug kk;=8
======
Or add MacroA():

Code: Select all

Dim u.s(7)
u(3)="kk"

Macro var(Array, value)
MacroA(Array)=value
EndMacro

var(u(3), 8)
Debug kk;=8
my pb for chinese:
http://ataorj.ys168.com
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: add MacroA Or MacroA()

Post by HanPBF »

Not a macro solution but an indirection.

Code: Select all

Structure Vars
	map Content.i()	
	array Index.s(0)
endStructure

define *V.Vars = AllocateStructure(Vars)
redim *V\Index(7)

*V\Index(3) = "kk"
*V\Content(*V\Index(3)) = 8

debug *V\Content(*V\Index(3))
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: add MacroA Or MacroA()

Post by gurj »

Thanks HanPBF ! might,This topic is bad.
my way:

Code: Select all

Global drs,kk,mbjw
Procedure StrToVal(s.s,value)
 Select s
  Case "drs":drs=value
  Case "kk":kk=value
  Case "mbjw":mbjw=value
 EndSelect
EndProcedure
StrToVal("kk",8)
Debug kk;=8
my pb for chinese:
http://ataorj.ys168.com
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: add MacroA Or MacroA()

Post by Demivec »

Even simpler:

Code: Select all

NewMap Vars.i()

;assign values
Vars("kk") = 8
Vars("mbjw") = 13
Vars("drw") = 4

;show selected values
Debug Vars("mbjw") ; =8
Debug Vars("kk") ; =13
Debug Vars("drw"); =4

;reassign a value
Vars("mbjw") = 59

;All vars:
ForEach Vars()
  Debug MapKey(Vars()) + " = " + Vars()
Next
Another native way is to use Runtime (maybe more complex in some ways):

Code: Select all

Define one, two, three, half5.d, half3.d
Runtime one, two, three, half5, half3

SetRuntimeInteger("one", 8)
SetRuntimeInteger("two", 2)
SetRuntimeInteger("three", 13)
SetRuntimeDouble("half3", 3.5)
SetRuntimeDouble("half5", 5.25)

Debug GetRuntimeInteger("one") ; = 8
Debug GetRuntimeInteger("three") ; = 13
Debug GetRuntimeInteger("two") ; = 2
Debug GetRuntimeDouble("half3") ; = 3.5
Debug GetRuntimeDouble("half5") ; = 5.25
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: add MacroA Or MacroA()

Post by gurj »

Thanks HanPBF and Demivec ! nice !
my pb for chinese:
http://ataorj.ys168.com
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: add MacroA Or MacroA()

Post by Lunasole »

Here is some unique native way :3
The key len can't be longer that 4 chars in unicode mode.

Code: Select all

; On modern machines there is no more need to think about RAM!
Global Dim Stuff.i ('zzzz')

Stuff('nice') = 512
Debug Stuff('nice') 
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: add MacroA Or MacroA()

Post by gurj »

Thanks Lunasole very much ! nice!
my pb for chinese:
http://ataorj.ys168.com
Post Reply