How do you access a field in a struct? [message #18326] |
Wed, 15 December 1999 00:00 |
Karri Kaksonen
Messages: 27 Registered: October 1999
|
Junior Member |
|
|
Hi,
I have a small problem with accessing my structs.
The complete program (that does not work) looks like:
pro beer
a = { $
beer: 1, $
icecream: 2 $
}
b = { $
milk: 0.60, $
beer: 1.25, $
icecream: 0.75, $
tea: 0.50 $
}
totalsum = 0.0
selection = tag_names(a)
for i=0,n_tags(a)-1 do totalsum=totalsum + a.(i) * b.(selection[i])
print, totalsum
end
When I run this program I get:
IDL> beer
% Type conversion error: Unable to convert given STRING to Long.
% Detected at: BEER 16 C:\RSI\IDL52\mri\beer.pro
% Type conversion error: Unable to convert given STRING to Long.
% Detected at: BEER 16 C:\RSI\IDL52\mri\beer.pro
1.80000
The funny thing is that it obviously replaced "beer" and "icecream"
with "milk" as it could not understand that b.('beer') is the same
as b.beer
Is there a way to pass the name of the structure field as a string?
--
Regards,
Karri Kaksonen
Picker Nordstar
|
|
|