Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formula for converting multi choice into a number
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01558333
Message ID:
01558344
Vues:
67
This message has been marked as a message which has helped to the initial question of the thread.
Based on Tore' suggestion:
*** To calculate value and let you have 6 CheckBoxes in the forms:
lnValue = 0
FOR lnFor = 1 TO 6
    WITH EVALUATE("thisform.Check"+TRANSFORM(lnFor))
         lnValue = IIF(.Value, BITSET(lnValue, m.lnFor-1))
    ENDWITH
NEXT
? lnValue

*** To Get it back:
lnValue = FieldWhereYouSave
FOR lnFor = 1 TO 6
    WITH EVALUATE("thisform.Check"+TRANSFORM(lnFor))
         .Value = BITTEST(lnValue, m.lnFor-1)
    ENDWITH
NEXT
>I believe you just answered my questions. So, first, thank you! The only thing I am not clear is how do you convert the stored sum into the choices? For example, if the stored number is 12. How would you convert this 12 into 4 and 8?
>
>>Why not use binary values?
>>
>>Choice 1 ---- 1
>>Choice 2 ---- 2
>>Choice 3 ---- 4
>>Choice 4 ---- 8
>>Choice 5 ---- 16
>>Choice 6 ---- 32
>>
>>Sum the values to store them. You can then easily retrieve which choices were selected.
>>
>>lnX = the sum
>>
>>To check if Choice 1 was selected : ?Bittest(lnX,0)
>>To check if Choice 2 was selected : ?Bittest(lnX,1)
>>To check if Choice 3 was selected : ?Bittest(lnX,2)
>>Note that the value after lnX is one lower than expected, since Bittest() is zero based.
>>
>>>Hi,
>>>
>>>I am looking for a formula (if possible) to convert a multiple choice(s) into a number. Kind of like the VFP Anchor property bit value works. Here is my example:
>>>Choice 1 ---- ##
>>>Choice 2 ---- ##
>>>Choice 3 ---- ##
>>>Choice 4 ---- ##
>>>Choice 5 ---- ##
>>>Choice 6 ---- ##
>>>
>>>Each choice above would have a number (##). Then when a user checks any number of choices (from 1 to 6), the "total" number is calculated. This "total" number should be unique for any combination of the selected choices. So that this number can be used (in reverse) to see what choices it represent.
>>>Any suggestions?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform