Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Dan Baker
  Where is Dan Baker?
 Effort of the Poconos
 Pennsylvania - United States
 Dan Baker
 To: Greg Green
  Where is Greg Green?
 
 Georgia - United States
 Greg Green
 Tags
Subject: RE: Can an Option Group have Number Options?
Thread ID: 365373 Message ID: 365811 # Views: 43 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Monday, December 31, 2012 4:36:58 PM         
   


Greg and Stefan,

Thanks for these suggestions.   i was not familiar with the access and assign methods for properties, so this was a good learning exercise for me.

Another thing I learned is that when creating a subclass for a property or object, you really don't need to constantly close the form to revise a class method.   You can simply write code to the form object's method.   Later on you can finalize the class by copying the object's method code into the class.   For me, this takes away the pain of working with classes that are not quite mature.

Maybe that's an obvious thing, but it's a new concept to me.   So appreciate pointing me in that direction.

My original goal was to find a better way to access an option group in a table.

For example, when creating a cursor, if my real life options are red, green, and blue, I would rather look up "red" or "green" or "blue", not 1, 2 or 3.   So of the following SQL statements, the first is superior because it's self-documenting:

SELECT * from table1 WHERE color = "blue" INTO CURSOR table1_c

SELECT * from table1 WHERE color = 1 INTO CURSOR table1_c

My solution, then, is to create two fields in table1:

Fieldname  Type          Description    
---------  ----          -----------      
color_num  Integer    && Stores the OptionGroup value by ControlSource reference

color_chr  Character  && Written by InteractiveChange event of the OptionGroup


At design-time, I make the captions what I want to enter into my color_chr field:

opn1.Option1.Caption is "Telecom operator"
opn1.Option2.Caption is "Software vendor"... and so forth.

And in the InteractiveChange event code, I capture the lower case version of the first word in the Option captions as follows:

LOCAL macro as String 

macro = "This.Option"+TRANSFORM(This.Value)+".Caption"
macro = LOWER(LEFT(LTRIM(&macro),AT(" ",&macro+" ")))   && Get first word only

SELECT table1
replace comptype WITH macro IN table1

So this works for me.   The only thing is I need to be careful to not make manual entries in the fields that put the two color fields out of sync.

So I'm curious if my solution is ok or if there's a better way, or I'm missing something.

Dan B.






> As Stefan noted, define a custom class of the optiongroup. Now in open the Edit Properties (you can use PEME here) and select the Value property for the optiongroup class. Now select the checkbox "Access" and save. This will add a new method to the optiongroup called value_access.
>
> Add this to the code to return a zero based index:
>
>
> RETURN this.Value-1
> 

>
> For a list of values you might add the following code:
>
>
> DO CASE
> CASE this.Value = 1
>    RETURN "Left"
> CASE this.Value = 2
>    RETURN "Right"
> CASE this.Value = 3
>    RETURN "Center"
> ENDCASE
> 


ENTIRE THREAD

Can an Option Group have Number Options? Posted by Dan Baker @ 12/25/2012 2:46:45 PM
RE: Can an Option Group have Number Options? Posted by David Mustakim @ 12/25/2012 4:40:24 PM
RE: Can an Option Group have Number Options? Posted by Anders Altberg @ 12/25/2012 5:46:34 PM
RE: Can an Option Group have Number Options? Posted by Greg Green @ 12/25/2012 6:16:55 PM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 12/26/2012 2:27:04 PM
RE: Can an Option Group have Number Options? Posted by Stefan Wuebbe @ 12/26/2012 3:24:46 PM
RE: Can an Option Group have Number Options? Posted by Greg Green @ 12/27/2012 8:13:21 PM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 12/31/2012 4:36:58 PM
RE: Can an Option Group have Number Options? Posted by David Mustakim @ 1/1/2013 7:24:53 PM
RE: Can an Option Group have Number Options? Posted by Rick Hodgin @ 1/1/2013 7:51:35 PM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 1/1/2013 8:35:31 PM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 1/1/2013 8:40:39 PM
RE: Can an Option Group have Number Options? Posted by David Mustakim @ 1/1/2013 9:13:40 PM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 1/2/2013 1:07:38 AM
RE: Can an Option Group have Number Options? Posted by Stefan Wuebbe @ 1/2/2013 9:39:57 AM
RE: Can an Option Group have Number Options? Posted by Dan Baker @ 1/2/2013 12:17:12 PM
RE: Can an Option Group have Number Options? Posted by Stefan Wuebbe @ 1/2/2013 12:22:09 PM
RE: Can an Option Group have Number Options? Posted by Jun Tangunan @ 12/26/2012 12:16:41 AM