Re: Little CREATE_STRUCT issue [message #43226] |
Thu, 24 March 2005 09:11 |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Thu, 24 Mar 2005 13:34:58 +0000, Ricardo Bugalho wrote:
> Hi,
> I want to use CREATE_STRUCT like this:
>
> myStruct = CREATE_STRUCT(['tag1', 'tag2'], [100, 200])
>
> Yes, I have a structure where all elements are of the same type.
> Is there any magic way to do it, or I'll just have to write a small
> function?
You can build it up "piece by piece" using CREATE_STRUCT's ability to
extend structures, like:
myStruct=create_struct('tag1',100)
myStruct=create_struct(myStruct,'tag2',200)
...
which could easily be made into a general function. This is inefficient
for large structures, since it copies and extends the structure once for
each tag, but at least it works.
I suspect RSI decided that if all your values are the same type, you could
just put them in an array and save yourself the trouble of making a
structure out of them... and maybe they have a point.
JD
|
|
|
|
Re: Little CREATE_STRUCT issue [message #43244 is a reply to message #43232] |
Thu, 24 March 2005 05:57  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ricardo Bugalho writes:
> I want to use CREATE_STRUCT like this:
>
> myStruct = CREATE_STRUCT(['tag1', 'tag2'], [100, 200])
>
> Yes, I have a structure where all elements are of the same type.
> Is there any magic way to do it, or I'll just have to write a small
> function?
There is no magic in computer programming. (Except,
of course, with objects.)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|