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

Home » Public Forums » archive » Re: Spin button widget??
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Spin button widget?? [message #45669] Mon, 26 September 2005 02:26 Go to previous message
peter.albert@gmx.de is currently offline  peter.albert@gmx.de
Messages: 108
Registered: July 2005
Senior Member
Hi David,

well, Edwards is right with his comment, double(0.1) is not the same as
0.1d:

IDL> print, double(0.1), format = '(f20.18)'
0.100000001490116119
IDL> print, 0.1d, format = '(f20.18)'
0.100000000000000006

The problem in the code is the variable "invInc", calculated from
"1d/state.increment". In my case invInc (more or less) equals 10 when
the increment is set to 0.1d, while it is somewhat smaller than 10 in
case of the increment being 0.1:

IDL> print, 1d / 0.1d, format = '(f10.7)'
10.0000000
IDL> print, 1d / double(0.1), format = '(f10.7)'
9.9999999

This difference later makes the variable "integerized" different to
LONG64(integerized) (used in the following IF statement), where
"CEIL(integerized)" is used to round to the nearesf fraction.

Well, and this is where things go wrong, as this IF statement just
takes care of cases where e.g. the starting value is something like
"2.4 times the increment". In that case FLOOR and CEIL just work fine
for the "up" and "down" event.

As a possible solution I would suggest to just count the multiples of
the increment instead of the value itself and to increase or decrease
just thie multiple: This can be done by adding a new tag to the "state"
structure, which is at first filled with "ROUND(start_value /
increment):

(in function cw_itupdownfield)
state = {VALUE: value, $
INCREMENT: increment, $
SPINTIME: spinTime, $
NNN: round(value / increment), $
UNITS: units}

Then, the function "cw_itupdownfield_updown" can get rid of the IF
statement ( if (integerized eq LONG64(integerized))), and instead two
lines of code like

state.nnn = keyword_set(down) ? state.nnn - 1 : state.nnn + 1
newvalue = state.nnn * state.increment

will do the trick.

Then the function "cw_itupdownfield_value" also needs one addiitional
line (after line 180:)

state.nnn = round(newvalue / state.increment)

I just gave it a quick check but it worked fine so far.

Best regards,

Peter
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Crisp characters in iTools
Next Topic: Re: Array juggling help needed

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

Current Time: Wed Oct 08 18:56:26 PDT 2025

Total time taken to generate the page: 0.00422 seconds