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

i have made further enhancements (2 new themes) and modifications (like renaming _type to _theme, removing _ivalue, allowing _value to accept either a logical or integer value then return the same, and some more) inside the class so i decided to rewrite this blog instead of cluttering the bottom part with lots of updates/notes; here which will make it longer.  so here is the revised blog:

as i have said before, i love simple things as sometimes those simple things are what's contributing to the bigger picture. my intention for this class is to replace the checkbox with something unique/unusual.  although for simple needs of toggling a return value of .t. or .f. or 1 or 0 checkbox is the best thing to turn to, it does not hurt to replace it with something a little bit unique which may add "appeal" to our form.   presenting switchbox:

q: so how can we use this new class?
a: as usual with classes you just need to drag it inside your form.  then in the init event of the instance of the class is where you need to assign the switchbox' different properties like theme and caption. in the image shown above, i used something like this:

switchbox1 init:
this._theme = 5
this._value = .t.

note:  default settings follow:

_value = .f.
_theme = 1
_caption = none

q:  what does none in the default caption means?
a:  in the tradition of vfp, in an absence of assigned caption, it will get the name of the of the object.  so when you don't touch the _caption property you will be seeing something like switchbox1, switchbox2....

q:  for whatever reason, i don't want to put any caption on the switchbox.  can i simply show the switchbox without any caption?
a:  yes!  just place in the init event of the instance of the class: 

this._caption = ''

q:  a checkbox class has a click event where we can  place commands.  can we do the same with switchbox?
a:  yes, but you need to use switchbox' shape1 click event for that and combine it with dodefault(), something like this:

switchbox shape1's click event:
dodefault()
* do something here

q:  what are the possible return value of this class?
a:  like the checkbox class, this class will return an integer value of  1 (on state) or 0 (off state) or .t. (on state) or .f. (off state) depending on the declaration used via _value property.  by default as mentioned though, it is set to a logical value of .f..

?thisform.switchbox1._value  && will return either .t., .f., 1 or 0 depending on the initial value we assign

q:  how about if we want the switchbox to start in an on state?
a:  just add any of these in the init event of the instance of the switchbox object inside the form:

this._value = 1    && sets it to on state initially, _value to be returned is either 1 or 0
this._value = .t&& sets it to on state initially, _value to be returned is either .t. or .f.
this._value = 0    && sets it to off state initially, _value to be returned is either 1 or 0

q:  checkbox can be toggled via clicking on its caption.  does this one have that attitude too?
a:  yes it does.

q:  the images seem to be tied up in c:\switchbox, how to make it work regardless of the path?
a.  on all the samples i gave, i do that to insure that interested users will properly see the images on the development stage.  however, if you want to remove that binding on specific folder location, do these:

remove the hardcoding of path i made inside the class on all occurrences; then add the images into your own project (other, other files, add).  one problem with that as i have said is you won't see those images while still in the developing stage.  those will be reflected properly only in the exe:

search all harcoding of path instances within the class, from:

this.parent.image1.picture = "c:\switchbox\swbox"+iif(this.parent._value = .f.,"on","off")+ transform(this.parent._theme)+".bmp"

into:

this.parent.image1.picture = "swbox"+iif(this.parent._value = .f.,"on","off")+transform(this.parent._theme)+".bmp"

the class i will give you includes 2 samples, the one shown above and this other one, replacing checkbox in a grid with something like this:

cool?

i have been a little bit intrigued by emerson's message that interested party may request a beta of his very cool new project instead of simply attaching a sample in that blog but thinking about it, yeah i love his new way, maybe not for the same reason that in mine is i would love to know who will be interested in this class for i was not able to know who had shown an interest on some of my previous ideas except for those who notify me by way of comments or email.

so for the first time, i will not be providing a link where you can download an attachment of this one.  if you are interested in this, post a comment below with your email address and i will be sending it to you.  post the request here under the comment section, not inside the forum.

sounds fair?  then i will say in advance to those who will be interested in using this class, enjoy!

p.s.  i would like to thank some guys in pointing to me some misrepresentation in the original blog content like woody and mike podjer whom without their comments i will simply fail to see such.

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
below:


http://www.coderisland.com/forum/viewtopic.php?f=10&t=254

23 Responses to New Switchbox Class (Revised & Enhanced)

  • Jijo says:

    Hi Jun,

    It looks great..

    can you send the download url to me?

    Here is my id

    jijopappachan at gmail dot com

    # It is better when you see it in its actual size as images here are distorted because I turn that into a jpg which looses image quality but with faster viewing.  You can check out for yourself the class in its actual state.  Sent on your email.

  • Ruslan says:

    Hi.

    It’s cool.

    can you send the download url to me?

    #Hello!  Please provide your email here.  I haven’t uploaded the sample in any website yet so I will email it to you from my harddisk.

  • Mike Yearwood says:

    You could add code to skin it with different appearances. Google this:

    toggle OR ROCKER AND switch

    #Thanks Mike!  I tried surfing the net for those but although some look cool, it became not when I resize it so it can be smaller.  I needed something that will not take up much space.  I actually designed another type, type 5, for that last night as I found the last four too big for my taste.

    I am always glad though whenever you pop in to give suggestion. Smile [:)]

  • mohsen says:

    hi

    it is very nice .

    #Thanks, if you are interested, please post your email address so I can send a copy to you.

  • anand kulkarni says:

    hi jun its nice . u r grate in introducing something new . great job 馃檪

    would u send it to me my email id

    an_kulk at yahoo dot co dot in

    thanks

    anand

    # Hello Anand, Please check your email.  Sent!

  • Gerrit says:

    Jun, Cool!

    Please send it to me: g dot b dot maseeATthorax dot umcg dot nl

    # Thanks!  Sent to your email

  • Greg Green says:

    please send a copy — thank you.

    anduril58 at hotmail dot com

    # Sent to your email.

  • Ruslan says:

    Hi!

    please send a copy — thank you.

    rulya-80 at mail ru

    # Sent to your email. The attachment includes the new type 4 switchbox.

  • wOOdy says:

    Hi Juan, how on earth came you to that observation: >> “Why the heck did  they not simply made it return a value of .T. or .F.?  “<<

    Of course the Checkbox does return a Logical. You just have to initialize the VALUE to a logical, and then you get a Logical .T. or .F. back. The “Undefined” state is done with a .NULL. in that case.

    See the HELP for CHECKBOX, it’s clearly documented.

    The reason why a checkbox can also react on numeric values is, that most SQL-Servers don’t know about true Logical values as xBase does, instead they are using 0/1 for that.

    Instead of that longwinded “AlLTRIM(STR(somevalue))” I just saw in your answer above, you can also use a simple “TRANS(SomeValue)” to make your code more elegant.

    Hello Wudy, Smile <img src=  

    I don’t know what I am thinking when I said that, LOL.  Here are my previous answers regarding a checkbox’ value  inside foxite forum:

    http://www.foxite.com/archives/0000185059.htm
    http://www.foxite.com/archives/0000171546.htm

    Regarding the ALLTRIM() + STR() vs TRANSFORM() approach though, actually I used both inside the class as those who already have my class can see. I used the ALLTRIM()+STR() approach once in the Click Event and TRANSFORM() on the other four events.  It just happens that when I copy-pasted to point out about removing the path hardcoding, I got the ALLTRIM() + STR() one. Plus since I really don’t mind which I use as they both give the same result, I did not pay attention to it.

    But TRANSFORM() is not always that elegant. There are cases where TRANSFORM() alone cannot give us what we need.  I will use a cheque amount as an example.  In our country, we need to enclose the numeric amount of a cheque with * without any spaces inbetween that and the numbers to avoid possible tampering/insertion of another number.  So if you do it like:

    namount=12345
    ? “****”+transform(namount,”9,999,999.99″)+”****”

    It will show a gap betwen the * and the first number.  So what we need to do is use both TRANSFORM() and ALLTRIM() to achieve what we need like this:
    ? “****”+alltrim(transform(namount,”9,999,999.99″))+”****”

    In which case transform() becomes dependent of the AllTrim() function like STR() do. 

    Nevertheless, I always appreciate it when you give comments to my blog to correct some misconceptions I am falsely sharing.  I would not like to do that intentionally. Thanks!

     P.S.  I guess I better correct it now while only few have read it to avoid sharing that false idea to some more people.  Again thanks for the notice.

  • chaim says:

    Hi,

    Can you plesase send me an example?

    Tnx

    #Chaim, the email bounced back.  Is the email address you put in the URL section of the comments accurate?  If it is, check your anti-spam and allow emails from my gmail account: sandstorm36 at gmail dot com.

    Then inform me again so I can resend the class including the samples to you.

  • Mike Potjer says:

    Hi Jun,

    FYI, the Checkbox class *does* support the Logical data type.  You can either set the ControlSource to something of Logical data type, or if the control is not bound, set the Value property to .F. or .T. in the property sheet.  The Value will then toggle between .F. and .T. when clicked.

    # Yes.  When I wrote that I may have been drunk, lol.  Shame on me.  Check these answers I gave before regarding that inside foxite:
    http://www.foxite.com/archives/0000185059.htm
    http://www.foxite.com/archives/0000171546.htm

  • profind says:

    can you send the download url to me?

    tnx

    #Sorry, there is no download URL.  I personally email those interested so if you want the class, give me your email address

  • sandstorm36 says:

    I have received some request directly from my email.  However, I just occasionally open my emails (yahoo and gmail) and so if you will like a speedier reply from me, better post your requests here as comment.  

    Plus do not forget to put a proper email address.  Change the “.” with “dot” and “@” with “at” for security purposes.

    Thanks!

    – jun (December 4, 2009)

  • Horacio says:

    Hola Jun.

    Te pido disculpas por escribirte a tu correo, pero no entiendo c贸mo enviar mi email.

    驴Podr铆as darme un ejemplo?

    Gracias.

    #Hola Horacio,

    No hay problema. Usted acaba de dar su direcci贸n de correo electr贸nico como 茅sta: junio arroba yahoo punto com. Esto
    es para evitar que las ara帽as agarrando la direcci贸n de correo
    electr贸nico publicado aqu铆, lo que dar谩 lugar posteriormente a una gran
    cantidad de spam en su correo electr贸nico.
    De
    todos modos, desde que le envi贸 la caja de distribuci贸n de clase
    original, me va a enviar ahora el m谩s reciente como se ha visto en el
    blog revisado.

    隆Salud!!

  • profind says:

    hugo at profind dot com dot ar

    # sent

  • Byron Santizo says:

    Podrias mandarme una copia de esta super clase mi correo es: ByronSantizo at hotmail dot com

    # Enviado a su correo electr贸nico

  • Ken Knorr says:

    kknorr at logoscms dot com

    #Sent to your email

  • wOOdy says:

    Hi Jun,

    In response to your response 馃槈 I always try to reduce my code, that’s why I normally prefer a single TRANS() instead of the ALLTR()+STR() combo (less code = less chance of errors)

    >> ? “****”+alltrim(transform(namount,”9,999,999.99″))+”****”

    Yes in that case you need an LTRIM(), because TRANS() reserves the unused spaces of your mask. Unless you would specify the mask with a preceeding “@B “, which would left-justify the output. Unfortunately the spaces are then ending up at the right end of the string ;), thus if you need both sides with stars, then there’s no way around usig a second function.

    As for the surrounding with stars: That’s best done with

    ? PADC(SomeValue,20,”*”)

    (where SomeValue could be your LTRI(TRAN()) again). Has the benefit of a constant resultlength, regardless what the TRIM will  come up with.

    As for your real switchbox-class: Have you thought about using a CONTROL baseclass instead of the container? It’s much easier to hide the unnecessary things.. (You can always change the baseclass afterwards with the ClasssBrowser tool, or just by USEing the VCX and replacing that one baseclass-field)

    BTW: I would be happy if you could email me your routines at “woody at prolib dot de”. And thanks for sharing your work and thoughts!  I especially like your interface-design stuff, it looks just great!

    #Thanks Woody!  And thanks for the above.  Information like that helps a lot of people not yet familiar with those things. 

    I am still new to a lot of things in VFP as well as making classes and when I created the switchbox class, that is where I first learn how _assign method can be used.  So when I thought of things to do, I work with those I am already familiar with.  But, I will play with your suggestion of using a Control Baseclass.

    I sent you all three classes so you can check on those and give more constructive observations.  Thanks!

  • Ligabue says:

    Congratulations your work is spectacular, I am even ashamed of my ability.

    Sorry for my English, I use google translator!

    my email:

    alexandreligabue at gmail dot com

    #Thanks for your compliment.  Sent to your email.

  • Felipe Melendez says:

    Thanks!

    please send me a copy!

    felipe_melendez at hotmail dot com

    #Welcome.  Please check your email

  • Elmer Alexander says:

    Gua magnifico podrias enviarme una copia de esta clase a mi correo e_alexs at hotmail dot com

    #Enviado.

  • Gaetano says:

    nice work! please send a copy to

    qgaetano@libero.it

    puoi inviarmi la tua splendida classe?

    qgaetano@libero.it

    Grazie Mille

    saluti dall’ITALIA

  • payday loan says:

    I want to thank the blogger very much not only for this post but also for his all previous efforts. I found weblogs.foxite.com to be very interesting. I will be coming back to weblogs.foxite.com for more information.

Leave a Reply

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