Strings tables

Share your advanced PureBasic knowledge/code with the community.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Strings tables

Post by Olliv »

To help mk-soft, after numbers, strings.

String tables

Caution : strings are NOT PROTECTED in an executable, even with single op xor.

Code: Select all

;*********************************************************************************************************************
Macro Table
	Define.I DimSLin0# MacroExpandedCount = #PB_Compiler_Line
	DataSection
	DimSData# MacroExpandedCount:
	Data.S ""
EndMacro
	
Macro EndTable(ArrName)
	DimSEndD# MacroExpandedCount:
	EndDataSection
	Define.I DimSLin1# MacroExpandedCount = #PB_Compiler_Line
	DimSTotal# MacroExpandedCount = 0
	For DimSI# MacroExpandedCount = ?DimSData# MacroExpandedCount To ?DimSEndD# MacroExpandedCount Step 2
		If PeekW(DimSI# MacroExpandedCount) = 0
			DimSTotal# MacroExpandedCount + 1
		EndIf
	Next
	DimSH# MacroExpandedCount = DimSLin1# MacroExpandedCount - DimSLin0# MacroExpandedCount - 1
	If DimSH# MacroExpandedCount
		DimSL# MacroExpandedCount = DimSTotal# MacroExpandedCount / DimSH# MacroExpandedCount
		DimSL# MacroExpandedCount - 1
		DimSH# MacroExpandedCount - 1
		Global Dim ArrName.S(DimSL# MacroExpandedCount, DimSH# MacroExpandedCount)
		Restore DimSData# MacroExpandedCount
		For DimSI# MacroExpandedCount = 0 To DimSH# MacroExpandedCount
			For DimSJ# MacroExpandedCount = 0 To DimSL# MacroExpandedCount
				Read.S ArrName(DimSJ# MacroExpandedCount, DimSI# MacroExpandedCount)
			Next
		Next
	EndIf
EndMacro






;- Example



Table+
	"red",		"magenta",
	"green",		"cyan",
	"blue",		"yellow"
EndTable(Cool)



Debug Cool(1, 2)

Last edited by Olliv on Sat Jun 22, 2019 4:10 pm, edited 1 time in total.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Strings tables

Post by ar-s »

Cool and fast. Thanks
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Strings tables

Post by Olliv »

Thank you for reply.

This request shows me, that two mistakes are within one of the code lines. Here we cannot build more than... one table.

This line below is false :

Code: Select all

;*****************************************************************************
  DimSH# MacroExpandedCount = DimSLin11 - DimSLin01 - 1
I am stupid. I will correct that. And I will add an other tip to try to be forgiven...
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Strings tables

Post by Olliv »

Now, it's ok. But do not forget this example must not to be used to store personnal datas which are not crypted in the final executable file.

This last detail will be the next tip : store datas easily and explain how to crypt them.
Post Reply