Counting Items in the DataSection?

Just starting out? Need help? Post your questions and find answers here.
User avatar
mk-soft
Always Here
Always Here
Posts: 6373
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
User avatar
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
User avatar
idle
Always Here
Always Here
Posts: 6064
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: 339
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
User avatar
Piero
Addict
Addict
Posts: 1094
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
User avatar
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

User avatar
Piero
Addict
Addict
Posts: 1094
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Counting Items in the DataSection?

Post by Piero »

Michael Vogel wrote: Sun Nov 09, 2025 10:22 pmThen I need 83 lines to catch the images
83? Hope you mean "83" as you did with MultiInclude :wink:

Code: Select all

Macro CatchIm(z=)
   CatchImage(MacroExpandedCount,?Label_#z#MacroExpandedCount)
EndMacro

CatchIm(00)
CatchIm(00)
PS: why not use MultiIncludes with 9 items for the leading zeros? Like:
MultiInclude(0)
MultiInclude()
MultiInclude()
…until 81
benubi
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Mar 29, 2005 4:01 pm

Re: Counting Items in the DataSection?

Post by benubi »

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.
User avatar
Piero
Addict
Addict
Posts: 1094
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Counting Items in the DataSection?

Post by Piero »

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