|
-
Mar 18th, 2022, 01:14 PM
#1
How to compare a saved number
It seem I did this many years ago in VB6 but can find an easy method in C#. Anyways, I’m try to save and retrieve options from a database as a single value. For this example I’ll use colors since they are easy to rattle off.
Red = 1
Green = 2
Blue = 4
Brown = 8
Yellow = 16
Orange = 32
The user can pick one or multiple colors. I’m saving the sum value of all the selected colors.
So for example if the user selects
Green, Brown and Yellow I would save 26 since 2+8+16 =26.
Or Brown and Orange would save 40 since 8+32=40
And if they just selected Blue then 4 would be saved.
Now let’s assume I have 11 returned from the database. Is there an easy way to determine that the color selections are Brown (8) + Green (2) + Red (1)?
I wrote a function that handles this but it seems pretty clunky and I have to believe there is a better way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|