Counting Items in the DataSection?

Just starting out? Need help? Post your questions and find answers here.
Post Reply
mk-soft
Always Here
Always Here
Posts: 6346
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Counting Items in the DataSection?

Post by mk-soft »

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 ...
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
Michael Vogel
Addict
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Counting Items in the DataSection?

Post by Michael Vogel »

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"
:
Did some tries with no success. I was generating Data.s code instead of IncludeBinary which is easier to test):

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
idle
Always Here
Always Here
Posts: 6050
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Counting Items in the DataSection?

Post by idle »

[引用]
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"
:
Did some tries with no success. I was generating Data.s code instead of IncludeBinary which is easier to test):

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
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.
viewtopic.php?t=52586
SMaag
Enthusiast
Enthusiast
Posts: 331
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: Counting Items in the DataSection?

Post by SMaag »

@Michael Vogel
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?
I use CodeCreation functions to do such things, especally to create Data Sections.

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()
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
Piero
Addict
Addict
Posts: 1064
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Counting Items in the DataSection?

Post by Piero »

[引用]
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
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Counting Items in the DataSection?

Post by Michael Vogel »

Perfect! Thank you!

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
Post Reply

Return to "Coding Questions"