Re: XForms: counter with wrap around?

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 5 May 99 06:31:11 PDT

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> How about adding a wrap around (modulus) to the counter object? For example
> if the counter is set to go from 1 to 10 with a step of 1, clicking the
> increase button with the counter at 10 would cause it to go back to 1.
>
> [...]
>
> A counter than can count an arbitrary sequence would be nifty too. Count up
> by primes, or skip 13, or in my case, skip TV channels that are programmed
> out, like a TV or VCR does.

Both of these things can be trivially accomplished using the counter
filter function.

For instance, the modulus or ring counter can be implemented with the
following code:

[...]

fl_set_counter_filter( counter, filter );
fl_set_counter_precision( counter, 0 );
fl_set_counter_bounds( counter, 1, 11 );
fl_set_counter_value( counter, 1 );
fl_set_counter_step( counter, 1, 1 );

[...]

static const char *filter( FL_OBJECT *ob, double value, int prec )

{

static char buffer[10];

if ( value == 11 ) {

value = 1;
fl_set_counter_value( ob, value );

} else if ( value == 0 )

value = 10;
fl_set_counter_value( ob, value );

}
sprintf( buffer, "%g", value );

return buffer;

}

This will count between 1 and 10 (or 10 and 1).

Implementing the second item is left as an exercise for the student.

spl

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/