Sign in to follow this  
Followers 0
Inverted

Advice about readable 2-dimensional array with comments

4 posts in this topic

I want to declare a (static) array which will get big. Example with two rows, imagine they will be 30 eventually after I fill them in:

Local $stringArray[2][2] = _
[ _
["This is the first item", "Description of it goes here"], _
["Another one ...", "Description again here"] _
]

That line breaking thing is annoying as hell. Another problem I faced is that I want to insert comments in the array, I tried this:

Local $stringArray[2][2] = _
[ _
;This is a comment for the first item
["This is the first item", "Description of it goes here"], _
;Comment for the second item
["Another one ...", "Description again here"] _
]

Finally I had to do this:

Local $stringArray[2][2] = _
[ _
["This is the first item", "Description of it goes here"], _   ;This is a comment for the first item
["Another one ...", "Description again here"] _   ;Comment for the second item
]

 

Is there a way to make it more readable and maybe avoid the underscores?

Share this post


Link to post
Share on other sites



inverted,

Is this more readable....?

#include <array.au3>

Local $stringArray[2][2]

$stringArray[0][0] = "This is the first item"       ; first item
$stringArray[0][1] = "Description of it goes here"  ; description
$stringArray[1][0] = "Another one ..."              ; comment
$stringArray[1][1] = "Description again here"       ; comment

_arraydisplay($stringArray)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Inverted

i would put the content of the array in a text file (pipe-delimited is may favorite) so it can be easily retrieved by _FileReadToArray. then you won't be needing to update your code each and every time the data changes. for example:

This is the first item|Description of it goes here|This is a comment for the first item
Another one|Description again here|Comment for the second item

note that you will get the comment at the third column of the array, which your script can simply ignore.

EDIT: and if i wasn't happy with the comment being in the array, i would fork _FileReadToArray and modify it to ignore the last element of each row. not too hard me thinks.

Edited by orbs

Share this post


Link to post
Share on other sites

Thanks for your answers , people.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0