FUNCTION Getval, text, x ;+ ; NAME: ; Getval ; PURPOSE: ; Read value for a variable from keyboard, allowing a RETURN to ; keep the old value, if the to-be-read variable is defined. ; CATEGORY: ; I/O ; CALLING SEQUENCE: ; Result = Getval( TEXT [, X]) ; INPUTS: ; TEXT : string to print out before asking for input ; OPTIONAL INPUT PARAMETER: ; X : Previous value to keep in case of RETURN ; KEYWORDS: ; none ; OUTPUTS: ; Result: users reply either same type as X (if supplied) or ; string ; SIDE EFFECTS: ; none ; RESTRICTIONS: ; ; PROCEDURE: ; ; MODIFICATION HISTORY: ; 21-Jun-1994 P.Suetterlin, KIS ;- on_error, 2 IF n_params() EQ 0 THEN text = 'Enter value' ;;; First, empty the keyboard buffer. We don't want to be faked by ;;; still waiting scrap WHILE (byte(get_kbrd(0)))(0) NE 0 DO BEGIN & END ch = '' IF (size(x))(1) NE 0 THEN BEGIN writeu, -1, text+' ('+string(x)+')' read, ch IF ch EQ '' THEN ch = x ELSE BEGIN s = size(x) CASE s(s(0)+1) OF 0 : 1 : ch = byte(fix(ch)) 2 : ch = fix(ch) 3 : ch = long(ch) 4 : ch = float(ch) 5 : ch = double(ch) 7 : 8 : message, 'Unable to handle structures' ENDCASE ENDELSE ENDIF ELSE REPEAT BEGIN writeu, -1, text read, ch ENDREP UNTIL ch NE '' return, ch END