Array name in a variable?

May 20, 2008
11,400
99
Syracuse, NY, USA
Is there a syntax which will allow me to reference an element of an array when I have the name of that array in a variable? Here's a simple partial example.
Code:
:showarray [arrayname]
echo ???????[0] & rem What do I put here if I want to see the 0th element in the array?
return
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Is there a syntax which will allow me to reference an element of an array when I have the name of that array in a variable? Here's a simple partial example.
Code:
:showarray [arrayname]
echo ???????[0] & rem What do I put here if I want to see the 0th element in the array?
return
It's a workaround, but this works.
Code:
:showarray [arrayname]
set b=%%%arrayname[0]
echo %b
return

Here it is explicitly.
Code:
v:\> setarray a[1]

v:\> set a[0]=foo

v:\> set arrayname=a

v:\> echo %%%arrayname[0]
%a[0]

v:\> set b=%%%arrayname[0]

v:\> set b
%a[0]

v:\> echo %b
foo
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Well, you *could* do that, but this is simpler:

Code:
setarray a[1]
set a[0]=foo
set arrayname=a
echo %[arrayname[0]]
Thanks! I tries many (often bizarre) constructions but not that one. Now that I see it, it makes sense.
 
Similar threads
Thread starter Title Forum Replies Date
D Parsing an array variable to an array does not work Support 5
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
vefatica SET /A and multidimensional array. Support 1
J WAD "setarray /f" only overwrites the first array var Support 2
J How to? Array sort according to multiple keys Support 3
S Documentation "DEFINED" vs. array elements Support 1
Frank watch an array variable in ide/bdebugger Support 2
S WAD SET problem - array element initialization Support 11
C Simple .bat question - dump contents of 2 dimensional array Support 2
Charles Dye Array limits Support 8
S How to access array elements? Support 5
S ARRAY enhancements Support 0
vefatica Leading spaces in array variables Support 13
A What is the fastest way to dump a array Support 4
Joe Caverly How to? Get name of current LIBRARY function? Support 4
vefatica Command name mix-up Support 3
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Chen Touboul When i try to delete an empty folder i got "the dirctoy name is invalid" Support 3
vefatica LIBRARY and file name completion? Support 4
vefatica PLAYSOUND requires 8-dot-3 name? Support 8
R Tree on FAT32 does not sort by name by default. Support 6
vefatica START /PGM "name with spaces.URL" fails Support 2
vefatica Can TCC complete this file name? Support 5
thorntonpg option /u not working The directory name is invalid Support 5
Dmitry L. Kobyakov WAD Start /pgm "name.htm" works improperly Support 4
E My echo full file name to the clipboard fails now. Support 2
Joe Caverly @NAME supports library functions Support 2
H file name completion on tcc21.01.61 Support 4
C See if a file name matches extended range. Support 15
vefatica Two @FUNCTIONs/aliases with the same name Support 4
x13 Function to get interface user-defined name? Support 10
nickles Command name parsing of GNU compilers Support 13
M Registered to machine-name? Support 7
P Rename files with ampersand in the name Support 1
mdwyer TCC 13 COPY: specified network name is no longer available. Support 5
R How to? Name completion only of directories? Support 3
I "IF" command in a variable does not expand redirection variable name Support 0
nickles Fixed Executing long command lines in a batch generates file name errors Support 16
Jay Sage Short File Name Won't Execute Support 4
rps Fixed V17 @name adding quote (") to result Support 5
vefatica FFIND /S, find directory with specified name? Support 7
jbanaszczyk Alias with space in the name Support 3
tmaynard Invalid item name "Lua" Support 6
MickeyF how to work with env var with special characters in the name Support 5
nickles WAD Variable name gets changed within FOR loop Support 2
B Why Does @GETDIR Repeat Selected Directory Name In Returned Value Support 7
noahcoad Fixed Can't @iniread a section w quotes in the name Support 6
M A UNC name failure... Support 28
M Why is an obviously invalid file name allowed? Support 2
T TCC reading TCMD.INI causing "Invalid item name" warnings and pauses Support 2

Similar threads