Jump to content

Advice about readable 2-dimensional array with comments


 Share

Recommended Posts

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?

Link to comment
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

Link to comment
Share on other sites

@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

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...