I’ve been working on a new program and decided I needed a numeric input spinner rather than using the GInput() gadget I wrote before. The GInput gadget works well and can limit to entry to numeric fields, but when using it with small numbers that are only 1 or 2 digits wide, it becomes confusing to use due to the cursor movement across that limited cell count. On top of that, there is numeric conversion from the string that GInput returns that must be dealt with in accommodating numeric sizes.
This new gadget is designed for small numbers (bytes) from 0 to 100. It can be used for number values up to 252. The last 3 values are reserved for gadget and form control. It increments and decrements with up, down, left, and right keys. It also allows for limiting the value to a lower and upper value.
Here I present the new function in my gadget library called GSpin(). This function can be used on an input form with other input gadgets or by itself. It will be included in the next release of the library. Essentially when it becomes active, the value is inversed and updated as the keystroked move the value up and down.
Code
; --------------------------------------
; Func..: GSpin(BYTE bN,x,y,bL,bM,bP)
; Desc..: Displays value and spin 0 to 100
; Params: bN = Window handle number
; x = Column of window to place spinner
; y = Row of window
; bL = Lowest value
; bM = Max value
; bP = initial value
; Req...: LIBWIN.ACT
; LIBSTR.ACT
; --------------------------------------
BYTE FUNC GSpin(BYTE bN,x,y,bL,bM,bP)
BYTE bD,bK,bR
CHAR ARRAY cL(4)
; Set working value
bD=bP
; Loop until exit
DO
; Convert to string & inverse
StrB(bD,cL)
StrPad(cL,32,3)
StrInv(cL,cL(0))
; Print value at spot
WPrint(bN,x,y,cL)
; Get key
bK=WaitKC()
; Process keystroke
if bK=KLEFT or bK=KPLUS or bK=KDOWN or bK=KEQUAL then
bD==-1
if bD<bL then bD=bL fi
elseif bK=KRIGHT or bK=KASTER or bK=KUP or bK=KMINUS then
bD==+1
if bD>bM then bD=bM fi
elseif bK=KESC then
bR=XESC
; Convert to string
StrB(bP,cL)
exit
elseif bK=KTAB then
bR=XTAB
; Convert to string
StrB(bP,cL)
exit
elseif bK=KENTER then
; Set return value
bR=bD
; Convert to string
StrB(bD,cL)
exit
fi
OD
; Redisplay value
StrPad(cL,32,3)
WPrint(bN,x,y,cL)
RETURN(bR)
Screenshots
The first is during editing:

The second shows the return value:
