What do I need MacroExpandedCount for?

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

What do I need MacroExpandedCount for?

Post by jacdelad »

Hello,
I know what it does, but I don't know what I could need it for. Has anyone ever used that, and why?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
skywalk
Addict
Addict
Posts: 4218
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: What do I need MacroExpandedCount for?

Post by skywalk »

I use this to auto-generate DataSection elements:

Code: Select all

;-{ MACROS
Macro HASH
  #
EndMacro
Macro DQ  ; Required in Macros since leading '#' conflicts with #DQ$ constant
  "
EndMacro
Macro QM  ; Required in Macros
  ?
EndMacro
Macro PC  ; Required in Macros
  %
EndMacro
Macro ds_MakeLabel(Label)
  QM#Label
EndMacro
Macro ENUM_RESET(n=0)
  Enumeration n
  EndEnumeration
EndMacro
Macro ds_PtrToLabel_Img(Label_Num)
  ; Create a pointer to an identical label named later.
  ; Enables automatically referencing the label in code since PB creates a pointer to the actual label.
  nImagesToLoad = MacroExpandedCount  ; Running count of images to load.
  DataSection
    Data.i QM#Label_Num   ; ?Label_Num
  EndDataSection
EndMacro
Macro ds_InclBin_Img(Label_Num, File)
  DataSection
    Label_Num:  : IncludeBinary File
    ;Label_Num#Q: ;FYI; No closing label since CatchImage() determines when to stop reading.
  EndDataSection
EndMacro
;-} MACROS
;-{ IMAGES:
; May also create #img_xxx constants for referencing if desired. Ex. #img_LOGOe = 3
ds_START(ds_ImagesToLoad)     ;-! ds_img()
ds_PtrToLabel_Img(Image_1)
ds_PtrToLabel_Img(Image_2)
; CREATE IMAGE LIST AND LABELS. Image_0 reserved for no image.
ds_InclBin_Img(Image_1, "..\img\blah.ico")
ds_InclBin_Img(Image_2, "..\img\blah2.png")
;-} IMAGES
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: What do I need MacroExpandedCount for?

Post by jacdelad »

That's...very specific and very cool. Thanks for sharing! Never thought about using datasections dynamically.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply