getting/setting value of unknown tag of structure??? [message #7653] |
Wed, 18 December 1996 00:00  |
alpha
Messages: 49 Registered: September 1996
|
Member |
|
|
Hello,
imagine the little program:
pro problem
read,mytagname,prompt="Enter Tagname: "
read,myvalue,prompt="This into it: "
mystruct=create_struct([mytagname,'test'],[myvalue,myvalue])
; this is easy and works
print,mystruct.test
; but how to get the myvalue via the first tagname?
print,mystruct.????
; ok, i can fetch it via tag_names:
thetagis=tag_names(mystruct)
thetagis=thetagis(0)
print,thetagis
; and my main problem is: how to set the unknown tag?
mystruct.???='THE NEW VALUE'
end
OK, any help needed...
Panther
PS: greetings to the housekeeper of wayward inodes...
--
Panther in the Jungle __..--''``\--....___ _..,_
-BELIEVE AND DECEIVE- _.-' .-/"; ` ``<._ ``-+'~=.
http://www.ang-physik _.-' _..--.'_ \ `(^) )
.uni-kiel.de/~hendrik ((..-' (< _ ;_..__ ; `'
|
|
|
Re: getting/setting value of unknown tag of structure??? [message #7749 is a reply to message #7653] |
Thu, 19 December 1996 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
In article <599fg1$18m@jungle.toppoint.de>, alpha@jungle.toppoint.de
(Hendrik Roepcke) writes:
|> pro problem
|> read,mytagname,prompt="Enter Tagname: "
|> read,myvalue,prompt="This into it: "
|>
|> mystruct=create_struct([mytagname,'test'],[myvalue,myvalue])
|>
|> ; this is easy and works
|> print,mystruct.test
|>
|> ; but how to get the myvalue via the first tagname?
|> print,mystruct.????
Are you aware of the following possibility:
; After creation of the structure:
tags = tag_names(mystruct)
ix = where(tags eq mytagname)
; This is not at typo ---------------------------v
if ix(0) ne -1 then print,mytagname+' = ',mystruct.(ix(0))
The tag index notation "struct.(tag_index)" is quite handy when
writing programs dealing with variable structures.
Stein Vidar
|
|
|