Re: working with restored values [message #11131] |
Mon, 02 March 1998 00:00 |
Cathy Campo
Messages: 7 Registered: October 1997
|
Junior Member |
|
|
> Cathy Campo (campo@gav.gat.com) writes:
>
> I am restoring a save file (i do not know the names of the
> variables in advance or their data type), and displaying some of the
> variable names to the user to choose from in a droplist.
>
> restore, 'junk.sav'
> help, output=tmpstr
> varlist = strarr(5)
> varlist = tmpstr(0:4)
> widget_control, droplist, set_value=varlist
>
> i would like to save the actual values of the variables in a
> array of pointers. (have this be the uvalue of the droplist?)
> but how would i do this?
>
> later i would be using the array of pointers in the event
> loop of the droplist to do calculations with the value chosen.
David Fanning wrote:
> I would try something like this:
>
> varValues = FltArr(5)
> For j=0,4 DO ok = Execute('varValues[j] = ' + varlist[j])
> Widget_Control, droplist, Set_Value=varlist, Set_UValue=varValues
David's suggestion would be good if I knew that all of the
variables were of data type 'float', but I don't. So using his
advice and my idea of pointers, I am able to do this:
restore, 'junk.sav'
help, output=tmpstr
varlist = strarr(5)
varlist = tmpstr[0:4]
widget_control, droplist, set_value=varlist
; store varlist in uvalue of base widget
ptr = ptrarr(5, /allocate_heap)
for i = 0, 4 do ok = execute('*ptr[i] = ' + varlist[i])
widget_control, droplist, set_uvalue=ptr
in the event loop i am able to do this:
; get back varlist from uvalue of base widget
widget_control, droplist, get_uvalue=ptr
nvars = n_elements(varlist)
for i = 0, nvars-1 do begin
print, varlist[i]
help, *ptr[i]
endfor
Cathy
|
|
|
Re: working with restored values [message #11132 is a reply to message #11131] |
Mon, 02 March 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Cathy Campo (campo@gav.gat.com) writes:
> I am restoring a large save file, and displaying some of the
> variable names to the user to choose from in a droplist.
>
> restore, 'junk.sav'
> help, output=tmpstr
> varlist = strarr(5)
> varlist = tmpstr(0:4)
> widget_control, droplist, set_value=varlist
>
> i would like to save the actual values of the variables in a pointer
> array or structure. (have this be the uvalue of the droplist?)
> but how would i do this?
>
> later i would be using the pointer array or structure in the event
> loop of the droplist to do calculations with the value chosen.
I presume from this that you do NOT know the names of the
variables in advance. I would try something like this:
varValues = FltArr(5)
For j=0,4 DO ok = Execute('varValues[j] = ' + varlist[j])
Widget_Control, droplist, Set_Value=varlist, Set_UValue=varValues
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|