*** i moved to my own blog site so to check on my future posts, please go to www.junblogs.com  ***

this tutorial is for the current or future switchbox’ users.  still on the who’s who stage, you will not find any attachment here.  what you will find here is the way how to transform the switchbox into an optionswitch.  let us take a look first at a couple of images below:

“coincidentally”, the selection itself shows one difference of optionswitch as against optoingroup.  it  is more colorful.  in addition, it doesn’t have the ugly lines around the caption.

like the optiongroup, optionswitch can only retain one on state.  so when you click on another switch, the previously on switch will be turned off to give way to the currently clicked switch.  again, without the ugly lines surrounding the caption in the case of an optiongroup.

there is really nothing that much to tell about an optiongroup or optionswitch as they both can do the same.  switchbox, on the other hand, has one advantage over it in that unlike an optiongroup it can return a value of 0 (all switches are on the off status).  while it is true that it can only have one on, i decided to allow it to return a 0 value.  who knows, someone may find some use for it?

so how then can we turn a couple of switchboxes into an optionswitch?  here goes:

1.    drag a switchbox into your form, change the various settings on its init event
2.    copy paste to create several instances
3.    change every copies’ settings as well
4.    select all then cut (ctrl+x)
5.    now create a container object, name it as contobox then press ctrl button then click on it or right-click on the container then choose edit
6.    press ctrl+v to paste all previously switchboxes that we cut inside that container
7.    you can optionally change the bordercolor like what i have shown above to make it appear better
8.    double-click container object and in its init event, paste these:

local swobject as character
for lnloop = 1 to this.objects.count
    swobject = "switchbox"+transform(lnloop)
    this.&swobject.._type = 5  && or whatever type of your choosing

9.    now create a method which will control the toggling to ensure that there will only one will remain in the on status.  click form – new method, type otoggle as name, and add a description to remind you of what that is.  go to that method and paste these:

lparameters lcswname
local swobject as character
for lnloop = 1 to thisform.contobox.objects.count
    swobject = "switchbox"+transform(lnloop)
    if upper(swobject) # upper(lcswname)
        thisform.contobox.&swobject.._value = .f.
        thisform.switchbox = m.lnloop

10.    finally, on every switchbox instance’s shape1 click event, paste these:


and there you have it.  an optionswitch. 

getting the current optionswitch value is as easy as this:


getting the caption of the currently selected (in the on state) switchbox is like this:

local lswitchboxcaption
lswitchboxcaption = "switchbox"+transform(thisform.switchbox)
messagebox(iif(thisform.switchbox=0,"all are on the off status!",;

i hope that this simple tutorial on turning the switchbox class into an optionswitch will do you good.  next posting will be my pre-christmas gift to interested users.  enjoy!

update: december 26, 2009

i already have submitted the classes for free and easy download to eric
for the download section of foxite, so you will see those pending the
decision of eric.  in addition, i have created a thread in coderisland
to have the same available for download.  please click on the link


One Response to Transmorphing SwitchBox into an OptionSwitch

Leave a Reply

Your email address will not be published. Required fields are marked *