any easier way of reading and writing to INI files?

Previous topic - Next topic

Gary

I have a fair amount of data in my projects stored in arrays and wondered if there was an easier way to dump and read an array to an INI file than doing the following

Code (glbasic) Select
INIPUT "pots","0,0,0",pots[0][0][0]
INIPUT "pots","0,0,1",pots[0][0][1]
INIPUT "pots","0,0,2",pots[0][0][2]
INIPUT "pots","0,0,3",pots[0][0][3]
INIPUT "pots","0,0,4",pots[0][0][4]
INIPUT "pots","0,0,5",pots[0][0][5]
INIPUT "pots","0,0,6",pots[0][0][6]
INIPUT "pots","0,1,0",pots[0][1][0]
INIPUT "pots","0,1,1",pots[0][1][1]
INIPUT "pots","0,1,2",pots[0][1][2]
INIPUT "pots","0,1,3",pots[0][1][3]
INIPUT "pots","0,1,4",pots[0][1][4]
INIPUT "pots","0,1,5",pots[0][1][5]
INIPUT "pots","0,1,6",pots[0][1][6]
INIPUT "pots","0,2,0",pots[0][2][0]
INIPUT "pots","0,2,1",pots[0][2][1]
INIPUT "pots","0,2,2",pots[0][2][2]
INIPUT "pots","0,2,3",pots[0][2][3]
INIPUT "pots","0,2,4",pots[0][2][4]
INIPUT "pots","0,2,5",pots[0][2][5]
INIPUT "pots","0,2,6",pots[0][2][6]
INIPUT "pots","0,3,0",pots[0][3][0]
INIPUT "pots","0,3,1",pots[0][3][1]
INIPUT "pots","0,3,2",pots[0][3][2]
INIPUT "pots","0,3,3",pots[0][3][3]
INIPUT "pots","0,3,4",pots[0][3][4]
INIPUT "pots","0,3,5",pots[0][3][5]
INIPUT "pots","0,3,6",pots[0][3][6]


INIPUT "pots","1,0,0",pots[1][0][0]
INIPUT "pots","1,0,1",pots[1][0][1]
INIPUT "pots","1,0,2",pots[1][0][2]
INIPUT "pots","1,0,3",pots[1][0][3]
INIPUT "pots","1,0,4",pots[1][0][4]
INIPUT "pots","1,0,5",pots[1][0][5]
INIPUT "pots","1,0,6",pots[1][0][6]
INIPUT "pots","1,1,0",pots[1][1][0]
INIPUT "pots","1,1,1",pots[1][1][1]
INIPUT "pots","1,1,2",pots[1][1][2]
INIPUT "pots","1,1,3",pots[1][1][3]
INIPUT "pots","1,1,4",pots[1][1][4]
INIPUT "pots","1,1,5",pots[1][1][5]
INIPUT "pots","1,1,6",pots[1][1][6]
INIPUT "pots","1,2,0",pots[1][2][0]
INIPUT "pots","1,2,1",pots[1][2][1]
INIPUT "pots","1,2,2",pots[1][2][2]
INIPUT "pots","1,2,3",pots[1][2][3]
INIPUT "pots","1,2,4",pots[1][2][4]
INIPUT "pots","1,2,5",pots[1][2][5]
INIPUT "pots","1,2,6",pots[1][2][6]
INIPUT "pots","1,3,0",pots[1][3][0]
INIPUT "pots","1,3,1",pots[1][3][1]
INIPUT "pots","1,3,2",pots[1][3][2]
INIPUT "pots","1,3,3",pots[1][3][3]
INIPUT "pots","1,3,4",pots[1][3][4]
INIPUT "pots","1,3,5",pots[1][3][5]
INIPUT "pots","1,3,6",pots[1][3][6]

and a lot more arrays after this as well :(


I tried setting up a couple of nested loops and generating the variable names from that but it doesnt seem to like it

Any ideas?

Thanks
Gary

Moru

How does the code look that you tried? It's probably easier to save your arrays to binary files though, takes less space and not so easy to change for the wannabe hacker :-)

Gary

well the code I tried was something like

Code (glbasic) Select
FOR a = 0 TO 4
FOR b = 0 TO 3
FOR c = 0 TO 6
pots[a][b][c]=INIGET$("pots",a+","+b+","+c)
NEXT
NEXT
NEXT


Which im sure threw up some errors on the name before but just checked it and it seems to work fine now, wierd.

How do you do a binary file then? I thought the only way of saving things off was via the ini file? Not that I'm that worried about hackers etc but would be handy to know especially if it saves time in loading and saving

Thanks
Gary

Moru

Look into OPENFILE in the documentation, should give you examples for all commands. If not, ask again :-)

Gary


MrTAToad

Multiple-dimensioned arrays shouldn't be a problem - or perhaps you've found a bug!