RogerL Posted April 16, 2008 Share Posted April 16, 2008 (edited) I wish to build an array at run time and output the array to an ini file section. IniWriteSection doesn't seem to use the count in [0][0]. Simple example: Dim $names[8][2] $names[0][0] = 3; put count in here $names[1][0] = "Joe" $names[1][1] = 1 $names[2][0] = "Sid" $names[2][1] = 2 $names[3][0] = "Tom" $names[3][1] = 3 IniWriteSection ("Test.ini", "Names", $names) correctly ouptuts the three names (i.e. it starts at index1 not 0) but outputs four more lines of just '=' which I don't want. I know I can change array declaration from [8] to [4] in this example but in my program I have no idea how many there will be. (I was going to declare a large array and tell the user if the limit was reached) I have looked at using _ArrayAdd, e.gDim $names[1][2]; just large enough to hold count _ArrayAdd($names[1][0], "Joe") but ArrayAdd doesn't seem to be designed to work with 2-dimensional arrays? I would appreciate someone telling me how to do IniWriteSection from a variably sized array at run time. TIA, RogerL Edited April 16, 2008 by RogerL Link to comment Share on other sites More sharing options...
Triblade Posted April 16, 2008 Share Posted April 16, 2008 (edited) Try this: $names[0][0] = 3; put count in here ReDim $names[$names[0][0] + 1][2] ; This is the line I wrote for you :) $names[1][0] = "Joe" It resizes you array to $names[0][0] Call this ReDim allways after you variable resizing. From the helpfile: The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array. The number of dimensions must remain the same, or the old array will be forgotten during the ReDim. The array will retain the scope (Global or Local) that it had prior to resizing. Edit: Added quote Edited April 16, 2008 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
RogerL Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks TriBlade, ReDim worked a treat! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now