Welcome to Foxite.COM Community Weblog Sign in | Join | Help



New Switchbox Class (Revised & Enhanced)



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


Published Monday, November 30, 2009 1:07 AM by sandstorm36
Filed Under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: New Switchbox Class

Monday, November 30, 2009 5:02 AM by Jijo
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.

# re: New Switchbox Class

Monday, November 30, 2009 11:18 AM by Ruslan
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.

# re: New Switchbox Class

Monday, November 30, 2009 5:56 PM by Mike Yearwood
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 [:)]

# re: New Switchbox Class

Tuesday, December 01, 2009 5:26 AM by mohsen
hi
it is very nice .

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

# re: New Switchbox Class

Tuesday, December 01, 2009 10:14 AM by anand kulkarni
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!

# re: New Switchbox Class

Tuesday, December 01, 2009 11:26 AM by Gerrit
Jun, Cool!
Please send it to me: g dot b dot maseeATthorax dot umcg dot nl

# Thanks!  Sent to your email

# re: New Switchbox Class

Wednesday, December 02, 2009 12:24 AM by Greg Green
please send a copy -- thank you.

anduril58 at hotmail dot com

# Sent to your email.

# re: New Switchbox Class

Wednesday, December 02, 2009 9:24 AM by Ruslan
Hi!
please send a copy -- thank you.

rulya-80 at mail ru

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

# re: New Switchbox Class

Wednesday, December 02, 2009 11:31 AM by wOOdy
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.

# re: New Switchbox Class

Wednesday, December 02, 2009 12:13 PM by chaim
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.

# re: New Switchbox Class

Wednesday, December 02, 2009 7:54 PM by Mike Potjer
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

# re: New Switchbox Class (Revised &amp; Enhanced)

Thursday, December 03, 2009 10:34 PM by profind
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

# re: Requests via email

Friday, December 04, 2009 3:38 AM by sandstorm36
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)

# re: New Switchbox Class (Revised &amp; Enhanced)

Friday, December 04, 2009 11:13 AM by Horacio
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!!

# re: New Switchbox Class (Revised &amp; Enhanced)

Friday, December 04, 2009 5:25 PM by profind
hugo at profind dot com dot ar

# sent

# re: New Switchbox Class (Revised &amp; Enhanced)

Wednesday, December 09, 2009 7:24 PM by Byron Santizo
Podrias mandarme una copia de esta super clase mi correo es: ByronSantizo at hotmail dot com

# Enviado a su correo electrónico

# re: New Switchbox Class (Revised &amp; Enhanced)

Thursday, December 10, 2009 5:56 AM by Ken Knorr
kknorr at logoscms dot com

#Sent to your email

# re: New Switchbox Class (Revised &amp;amp; Enhanced)

Friday, December 11, 2009 12:10 PM by wOOdy
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!







# re: New Switchbox Class (Revised &amp; Enhanced)

Friday, December 11, 2009 9:44 PM by Ligabue
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.

# re: New Switchbox Class (Revised &amp; Enhanced)

Tuesday, December 15, 2009 6:54 PM by Felipe Melendez
Thanks!
please send me a copy!

felipe_melendez at hotmail dot com

#Welcome.  Please check your email

# re: New Switchbox Class (Revised &amp;amp; Enhanced)

Tuesday, December 15, 2009 10:42 PM by Elmer Alexander
Gua magnifico podrias enviarme una copia de esta clase a mi correo e_alexs at hotmail dot com

#Enviado.

# re: New Switchbox Class (Revised & Enhanced)

Monday, December 21, 2009 5:21 PM by Gaetano
nice work! please send a copy to
qgaetano@libero.it

puoi inviarmi la tua splendida classe?
qgaetano@libero.it

Grazie Mille
saluti dall'ITALIA

# Great article on weblogs.foxite.com

Saturday, February 20, 2010 11:06 PM by payday loan
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.

What do you think?

(required) 
required 
(required)