Hi Charles,
this is a sub which I would like to use in order to retrieve arrays from a text file. It is derived from function ExtractData of OxIde. I assume I could use override to apply the sub for other types too. I know there are more solutions possible with Oxygenbasic so maybe the sub could be improved a little bit? Yet I am still not sure if there is already an existing functionality provided with the include files.
Roland
include "$/inc/console.inc"
sub ExtractArray(string *s, k, int arr[], int c) 'array Id, dimension
'format: $keyword {data}
sys *array=@arr
sys a=instr(s,k)
if a=0 then print k " not found" : exit sub
a=instr a,s,"{" : if a=0 then print "Error in string " k : exit sub
b=instr a,s,"}" : if b=0 then print "Error in string " k : exit sub
if a then
a++ : st=mid s,a,b-a
end if
print "text = " & st
sys i=1,p=1
int n,l
for x=1 to c
i=instr p,st,","
if i=0 then exit for
l=i-p : n=mid(st,p,l) : array[x]=n
p=i+1 : i=p
next x
n=mid(st,p) : array[c]=n
end sub
'Test
string text = "
$color {
0x000000,0x800000,0x008000,0x808000,0x0000C4,0x800080,0x004080,0xC4C4C4,
0x808080,0xFF0000,0x00FF00,0xFFFF00,0x0000FF,0xFF00FF,0x00FFFF,0xFFFFFF,
0xA4A4A4,0xFFA080,0xA0FFA0,0xFFFFA0,0xA0A0FF,0xFFA0FF,0xA0FFFF,0xD4D4D4,
0xB4B4B4,0xFFDCBC,0xDCFFDC,0xFFFFDC,0xDCDCFF,0xFFDCFF,0xDCFFFF,0xE4E4E4
}
"
dim as int color(32)
ExtractArray text, "$color ", color[], 32
printl
for x=1 to 4
for y=1 to 8 : print "0x" hex(color[(x-1)*8 +y]) "," : next y
printl
next x
printl
printl "Enter..." : waitkey
.