Floating point input - %nrf

%rf (Edit Floating Point) creates an edit box and displays the value of the corresponding (DOUBLE PRECISION) argument. The number will be updated whenever the edit field is adjusted. The user will be prevented from creating an invalid or out of range number (see Floating point increase/decrease). Numbers are entered in decimal or exponent form. For example: -0.0748 or -7.48e-2.

By default the edit box will be made large enough to hold values in the current range, although the integer parameter n can be used to override this.

A call-back function is supplied using the caret (^) modifier. This function is called immediately a change is made.

For example, suppose you wanted to prompt for a complex number, and the user is allowed to supply this as an (x, y) pair or as an (r, θ) pair. The box should show the current number in both formats and any change in one format should be reflected in the other. Here is some sample code that has the desired effect.

      DOUBLE PRECISION x,y,r,theta
      COMMON x,y,r,theta
      INTEGER i,winio@
      EXTERNAL convert_to_xy,convert_to_polar
      i=winio@('%ca[Polar co-ordinates]%bg[grey]&')
      i=winio@('   %itx%`it=%ta&')
      i=winio@('   %ity%`it=%ta&')
      i=winio@('%ff   %itr%`it=%ta&')
      i=winio@('   %fn[Symbol]%itq%sf  =%ta&')
      INTEGER FUNCTION convert_to_polar()
      DOUBLE PRECISION x,y,r,theta,tiny
      COMMON x,y,r,theta
      INTEGER FUNCTION convert_to_xy()
      DOUBLE PRECISION x,y,r,theta
      COMMON x,y,r,theta

A grave accent format modifier (`) is used to make the control read-only. In this form no surrounding box is supplied, and the value displayed can only be changed by the program, using WINDOW_UPDATE@ to reflect the changes.

The %co (Options for Edit) format is used to modify the way that %rf (Edit Floating Point) and %rd (Edit Integer) call-back functions behave.



Copyright © 1999-2024 Silverfrost Limited