comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How do you access a field in a struct?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How do you access a field in a struct? [message #18326] Wed, 15 December 1999 00:00
Karri Kaksonen is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Changing elements in structures
Next Topic: Re: Old Question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:23:19 PDT 2025

Total time taken to generate the page: 0.00519 seconds