Simple adding of bulk data to array/list
Posted: Tue Aug 26, 2014 8:14 pm
Greetings to all,
is there a way to initialize array as in C?
So, instead of this:
is there some elegant way such as:
I could use something like this, for example:
but it just seems to be a little overkill (since I have to convert data from string to quad and it just seems wrong to begin with...), so I hope I am missing out something big (wouldn't be the first time
).
I am close to assembling PDF417 library for PureBasic which I will gladly share owing to the fact there is not to many useful (free) information on the web and I need to stack multiple data tables in the library (few thousands numbers in several predefined arrays) so it would really be handy not to write ~4000 lines of code just to initialize arrays.
is there a way to initialize array as in C?
So, instead of this:
Code: Select all
Fa(0) = 361
Fa(1) = 575
Fa(2) = 922
Fa(3) = 525
Fa(4) = 176
Fa(5) = 586
Fa(6) = 640
Fa(7) = 321
Fa(8) = 536
Fa(9) = 742
Fa(10) = 677
Fa(11) = 742
Fa(12) = 687
Fa(13) = 284
Fa(14) = 193
Fa(15) = 517
Fa(16) = 273
Fa(17) = 494
Fa(18) = 263
Fa(19) = 147
Fa(20) = 593
Fa(21) = 800
Fa(22) = 571
Fa(23) = 320
Fa(24) = 803
Fa(25) = 133
Fa(26) = 231
Fa(27) = 390
Fa(28) = 685
Fa(29) = 330
Fa(30) = 63
Fa(31) = 410
Code: Select all
Fa() = {361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410}
Code: Select all
Procedure Split(Array StringArray.s(1), StringToSplit.s, Separator.s = ", ")
Protected c = CountString(StringToSplit, Separator)
Protected i, l = StringByteLength(Separator.s)
Protected *p1.Character = @StringToSplit
Protected *p2.Character = @Separator
Protected *p = *p1
ReDim StringArray(c)
While i < c
While *p1\c <> *p2\c
*p1 + SizeOf(Character)
Wend
If CompareMemory(*p1, *p2, l)
CompilerIf #PB_Compiler_Unicode
StringArray(i) = PeekS(*p, (*p1 - *p) >> 1)
CompilerElse
StringArray(i) = PeekS(*p, *p1 - *p)
CompilerEndIf
*p1 + l
*p = *p1
EndIf
i + 1
Wend
StringArray(c) = PeekS(*p)
ProcedureReturn c
EndProcedure

I am close to assembling PDF417 library for PureBasic which I will gladly share owing to the fact there is not to many useful (free) information on the web and I need to stack multiple data tables in the library (few thousands numbers in several predefined arrays) so it would really be handy not to write ~4000 lines of code just to initialize arrays.