Counting Items in the DataSection?
Re: Counting Items in the DataSection?
In the meantime, I no longer understand what it's all about.
Some things are far too complicated. Best as it says in the PB help ...
Some things are far too complicated. Best as it says in the PB help ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- Michael Vogel
- Addict

- Posts: 2823
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Counting Items in the DataSection?
I need to add tons of images into a datasection and catch these images, so labels are needed. But how to create an IncludeBinary using a filename similar to the label?
The result should be something like this:
Did some tries with no success. I was generating Data.s code instead of IncludeBinary which is easier to test):
The result should be something like this:
Code: Select all
Label_01:
IncludeBinary Path# + "Image_01.png"
Label_02:
IncludeBinary Path# + "Image_02.png"
:Code: Select all
#Q=#DOUBLEQUOTE$
Macro Label(part1,part2)
part1#part2:
EndMacro
Macro Image(part1,part2)
IncludeBinary part1 + #Q+part2.jpg+#Q
EndMacro
Macro Datax(label)
Data.s "label"
EndMacro
#ImagePath= "."
Macro LabelData(Index)
;Label(Label_,MacroExpandedCount)
Label(Label_,Index)
;IncludeBinary #ImagePath + #Q+Index.jpg+#Q
;Image(#ImagePath,Index)
Datax(Index)
Data.s #Q+Index+#Q
EndMacro
DataSection
LabelData(ab)
LabelData(cd)
EndDataSection
Restore ab:
Read.s a.s
Debug aRe: Counting Items in the DataSection?
That's where you use a packer like ezpack so you can extract a single file or multiple files or all files to memory from the pack dynamically.Michael Vogel wrote: Fri Nov 07, 2025 6:55 pm I need to add tons of images into a datasection and catch these images, so labels are needed. But how to create an IncludeBinary using a filename similar to the label?
The result should be something like this:Did some tries with no success. I was generating Data.s code instead of IncludeBinary which is easier to test):Code: Select all
Label_01: IncludeBinary Path# + "Image_01.png" Label_02: IncludeBinary Path# + "Image_02.png" :Code: Select all
#Q=#DOUBLEQUOTE$ Macro Label(part1,part2) part1#part2: EndMacro Macro Image(part1,part2) IncludeBinary part1 + #Q+part2.jpg+#Q EndMacro Macro Datax(label) Data.s "label" EndMacro #ImagePath= "." Macro LabelData(Index) ;Label(Label_,MacroExpandedCount) Label(Label_,Index) ;IncludeBinary #ImagePath + #Q+Index.jpg+#Q ;Image(#ImagePath,Index) Datax(Index) Data.s #Q+Index+#Q EndMacro DataSection LabelData(ab) LabelData(cd) EndDataSection Restore ab: Read.s a.s Debug a
viewtopic.php?t=52586
Re: Counting Items in the DataSection?
@Michael Vogel
you need my CodeCreation Modul from
https://github.com/Maagic7/PureBasicFra ... reation.pb
This is the outout
DataSection
File_0: : IncludeBinary "File_0.jpg"
File_1: : IncludeBinary "File_1.jpg"
File_2: : IncludeBinary "File_2.jpg"
File_3: : IncludeBinary "File_3.jpg"
File_4: : IncludeBinary "File_4.jpg"
File_5: : IncludeBinary "File_5.jpg"
File_6: : IncludeBinary "File_6.jpg"
File_7: : IncludeBinary "File_7.jpg"
File_8: : IncludeBinary "File_8.jpg"
File_9: : IncludeBinary "File_9.jpg"
EndDataSection
I use CodeCreation functions to do such things, especally to create Data Sections.I need to add tons of images into a datasection and catch these images, so labels are needed. But how to create an IncludeBinary using a filename similar to the label?
you need my CodeCreation Modul from
https://github.com/Maagic7/PureBasicFra ... reation.pb
Code: Select all
; UseModule CC
;
NewList lstFiles.s()
Define I, code$
For I = 0 To 9
AddElement(lstFiles())
lstFiles() = "File_" + Str(I) + ".jpg"
Next
; CREATING the DataSection
I=0
CC::ClearCode()
CC::ADD("DataSection", CC::#CC_SHR_AFTER)
ForEach lstFiles()
code$ = GetFilePart(lstFiles()) ; get only the Filename
code$ = Left(code$, FindString(code$, ".")-1)
code$ = code$ + ": : IncludeBinary " + Chr('"') + lstFiles() + Chr('"')
Debug code$
CC::ADD(code$)
Next
CC::ADD("EndDataSection", CC::#CC_SHL_BEFORE)
CC::CopyToClipBoard()
DataSection
File_0: : IncludeBinary "File_0.jpg"
File_1: : IncludeBinary "File_1.jpg"
File_2: : IncludeBinary "File_2.jpg"
File_3: : IncludeBinary "File_3.jpg"
File_4: : IncludeBinary "File_4.jpg"
File_5: : IncludeBinary "File_5.jpg"
File_6: : IncludeBinary "File_6.jpg"
File_7: : IncludeBinary "File_7.jpg"
File_8: : IncludeBinary "File_8.jpg"
File_9: : IncludeBinary "File_9.jpg"
EndDataSection
Re: Counting Items in the DataSection?
Michael Vogel wrote: Fri Nov 07, 2025 6:55 pm I need to add tons of images into a datasection and catch these images, so labels are needed. But how to create an IncludeBinary using a filename similar to the label?
The result should be something like this:Code: Select all
Label_01: IncludeBinary Path# + "Image_01.png" Label_02: IncludeBinary Path# + "Image_02.png"
Code: Select all
; Path and index must be literal strings or constants, AND FILES MUST EXIST
Macro dq : "
EndMacro
Macro IncludeBin(z=)
Label_#z#MacroExpandedCount: ; starts with 1
IncludeBinary #binpath + "Image_"+dq#z#dq+MacroExpandedCount+".jpg"
EndMacro
#binpath = "/Users/Michael/Desktop/"
DataSection
IncludeBin(00)
IncludeBin(00)
EndDataSection- Michael Vogel
- Addict

- Posts: 2823
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Counting Items in the DataSection?
Perfect! Thank you!
Don't think your solution can be topped...
My code will look a little bit like this...
Don't think your solution can be topped...
Code: Select all
; Piero's code, I just added Data.s for testing...
Macro dq : "
EndMacro
Macro Label(counter)
Label_#counter:
EndMacro
Macro IncludeBin(z=)
Label(z)
Data.s #binpath + "Image_"+dq#z#dq+".jpg"; only for testing
;IncludeBinary #binpath + "Image_"+dq#z#dq+".jpg"
EndMacro
#binpath = "/Users/Michael/Desktop/"
DataSection
IncludeBin(001)
IncludeBin(yep)
EndDataSection
; Quick Check
Restore Label(yep)
Read.s s.s
Debug s
My code will look a little bit like this...
Code: Select all
Macro dq : "
EndMacro
Macro Label(counter)
Label_#counter:
EndMacro
Macro IncludeBin(z=)
; Label(z)
Label(MacroExpandedCount)
; Data.s #binpath + "Image_"+dq#z#dq+".jpg"
; Data.s #binpath + "Image_"+dq#MacroExpandedCount#dq+".jpg"
; IncludeBinary #binpath + "Image_"+dq#z#dq+".jpg"
IncludeBinary #binpath + "Image_"+dq#MacroExpandedCount#dq+".jpg"
EndMacro
Macro MultiInclude()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
IncludeBin()
EndMacro
#binpath = "/Users/Michael/Desktop/"
DataSection
MultiInclude()
MultiInclude()
MultiInclude()
MultiInclude()
MultiInclude()
MultiInclude()
MultiInclude()
MultiInclude()
IncludeBin()
IncludeBin()
IncludeBin()
EndDataSection
; Then I need 83 lines to catch the images, cool would be something like this (doesn't work of course)...
For i=1 To 83
CatchImage(i,?Label(i))
Next i
Re: Counting Items in the DataSection?
83? Hope you mean "83" as you did with MultiInclude
Code: Select all
Macro CatchIm(z=)
CatchImage(MacroExpandedCount,?Label_#z#MacroExpandedCount)
EndMacro
CatchIm(00)
CatchIm(00)MultiInclude(0)
MultiInclude()
MultiInclude()
…until 81
Re: Counting Items in the DataSection?
You could also zip all those image files, include the zip and then catch the images using the packer library with the new CatchPack command.
I'm not sure if the packer library would support self extracting archives out of the box but that could be an alternative especially if you'd like to dynamically change the zip content (later) without changing the main program. You could use WinRar to create the archive, in case the packer lib only supports reading from the "self-extracting archive". WinRar itself can use the zip archive commentary string at the file's end (up to 64k) to store configuration/installer settings, and this is an additional space for "meta data" you could make use of.
I'm not sure if the packer library would support self extracting archives out of the box but that could be an alternative especially if you'd like to dynamically change the zip content (later) without changing the main program. You could use WinRar to create the archive, in case the packer lib only supports reading from the "self-extracting archive". WinRar itself can use the zip archive commentary string at the file's end (up to 64k) to store configuration/installer settings, and this is an additional space for "meta data" you could make use of.
Re: Counting Items in the DataSection?
Again, about leading zeros (not very easy to find on Forum…) and because it can also be useful when unpacking:
Code: Select all
n = 11
n-1
k=Len(Str(n))
For i=0 to n
Debug "Label_"+ RSet(Str(i),k,"0") +~": : IncludeBinary \"Image_"+ RSet(Str(i),k,"0") +~".jpg\""
Next
