FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

CONTROLS

Handle multiple Check boxes and radio buttons


I use bits to keep track of a bunch of check boxes or radio buttons. Works equally well for either, although I normally do it for check boxes. So a long int holds a lot of data 32 control values).

'
LOCAL FN GetControlVal(DLOGptr&,whichItem):' values a check box
  DIM rect;8:' common rect
  CALL GETDITEM(DLOGptr&,whichItem,theType,theHandle&,rect):' read
END FN=FN GETCTLVALUE(theHandle&):' get the value
'
LOCAL FN SetControlVal(DLOGptr&,whichItem,theVal)
  DIM rect;8:' common rect
  CALL GETDITEM(DLOGptr&,whichItem,theType,theHandle&,rect):' read
  CALL SETCTLVALUE (theHandle&,theVal):' show if its on or off
END FN
'
LOCAL FN decodeBitControls(DLOGptr&,startCtrl,endCtrl,theBits&)
  DEFSTR LONG
  bitVal&=1
  FOR count=startCtrl TO endCtrl:' loop through all of the controls
    LONG IF theBits& AND BIT(bitVal&):' see if this bit is set
' puts a check mark in the box
      FN SetControlVal(DLOGptr&,count,1)
    XELSE:' turn off the control
' remove check mark in the box
      FN SetControlVal(DLOGptr&,count,0)
    END IF
    INC(bitVal&):' point to next bit position
  NEXT count
  DEFSTR WORD
END FN
'
LOCAL FN encodeBitControls(DLOGptr&,startCtrl,endCtrl)
  DEFSTR LONG
  bitVal&=1:' starting value for this counter
  theBits&=0:' the result we need back
  FOR count=startCtrl TO endCtrl:' loop through all of the controls
' set if this is checked ON
    LONG IF FN GetControlVal(DLOGptr&,count)
' add in the new bit position value
      theBits&=theBits&+BIT(bitVal&)
    END IF
    INC(bitVal&):' point to next bit position
  NEXT count
  DEFSTR WORD
END FN=theBits&
'

Keep in mind the controls (boxes et al) need to be in a numbered sequential fashion. But I find this makes it easy to set a pile of them or store all those lousy values).

Mel Patrick