Maths/Techy (VB) question...
Discussion
Hi,
Long shot but...
does anyone know how to/whether you can reverse engineer a binomial (I believe that's what they're called. Basically when you use a number to represent a combination of selected options). I know the options available and can compare a number to the options if you see what I mean.
Also, any advise/resources on using binomials would be great too!
Thanks,
Phil.
Long shot but...
does anyone know how to/whether you can reverse engineer a binomial (I believe that's what they're called. Basically when you use a number to represent a combination of selected options). I know the options available and can compare a number to the options if you see what I mean.
Also, any advise/resources on using binomials would be great too!
Thanks,
Phil.
You mean a "bit field" I think. The idea is to use an "integer" or a "long" to store a set of flags, using each bit as a flag representing true or false.
You decide what each bit is going to represent and then you are faced with the tasks of being able to set or clear the bit and test its state. You do this using "bitwise operators", i.e. AND OR XOR etc that operate on longs and integers bit by bit, rather than "standard" logical operators that act on Booleans.
If you look up "bitwise operator" in the help you should get some examples.
You decide what each bit is going to represent and then you are faced with the tasks of being able to set or clear the bit and test its state. You do this using "bitwise operators", i.e. AND OR XOR etc that operate on longs and integers bit by bit, rather than "standard" logical operators that act on Booleans.
If you look up "bitwise operator" in the help you should get some examples.
Take a simple example of a standard 3 lamp traffic light. It can exist in 1 of 4 states (green, amber, red, red+amber).
You could define each lamp as a number, carefully chosen to use only a single bit each, e.g.:
const lampgreen = 1 'Binary 001
const lampamber = 2 'Binary 010
const lampred = 4 'Binary 100
dim trafficlight as int
if (trafficlight OR lampgreen) then 'the green lamp is on
if (trafficlight OR lampred) then 'the red lamp is on
etc.
To get red and amber, you'd say:
trafficlight = lampred + lampamber 'value is 6, i.e. binary 110
>> Edited by pdV6 on Friday 16th January 13:47
You could define each lamp as a number, carefully chosen to use only a single bit each, e.g.:
const lampgreen = 1 'Binary 001
const lampamber = 2 'Binary 010
const lampred = 4 'Binary 100
dim trafficlight as int
if (trafficlight OR lampgreen) then 'the green lamp is on
if (trafficlight OR lampred) then 'the red lamp is on
etc.
To get red and amber, you'd say:
trafficlight = lampred + lampamber 'value is 6, i.e. binary 110
>> Edited by pdV6 on Friday 16th January 13:47
Sure...
Basically - for each person there are a number of parameters and each parameter has a number of options... I'll use database naming as an example (it's simpler and more generic) if that's OK!
Person: Phil
____________ Insert __ Update __ Delete __ Select
table_name1 __ Yes _____ No _____ No _____ Yes
table_name2 __ No _____ Yes _____ Yes _____ No
and so on...
the "20" options would be a continuation of the insert, update etc.
Does that make sense?
Cheers,
Phil
Edited because the HTML for the table didn't work (it did in the preview!)
>> Edited by chim_knee on Friday 16th January 15:41
Basically - for each person there are a number of parameters and each parameter has a number of options... I'll use database naming as an example (it's simpler and more generic) if that's OK!
Person: Phil
____________ Insert __ Update __ Delete __ Select
table_name1 __ Yes _____ No _____ No _____ Yes
table_name2 __ No _____ Yes _____ Yes _____ No
and so on...
the "20" options would be a continuation of the insert, update etc.
Does that make sense?
Cheers,
Phil
Edited because the HTML for the table didn't work (it did in the preview!)
>> Edited by chim_knee on Friday 16th January 15:41
chim_knee said:
Person: Phil
____________ Insert __ Update __ Delete __ Select
table_name1 __ Yes _____ No _____ No _____ Yes
table_name2 __ No _____ Yes _____ Yes _____ No
I dont quite 'get' what you want to do, but you can use a loop to help generate a number with each bit representing each of thoes options using a loop.
e.g.
Dim table_idx
Dim outflags As Long
For table_idx = 0 To (mytables.count-1)
If mytables(table_idx).canInsert Then outflags = outflags Or ((2 ^ (table_idx * 4) * &H1))
If mytables(table_idx).canUpdate Then outflags = outflags Or ((2 ^ (table_idx * 4) * &H2))
If mytables(table_idx).canDelete Then outflags = outflags Or ((2 ^ (table_idx * 4) * &H4))
If mytables(table_idx).canSelect Then outflags = outflags Or ((2 ^ (table_idx * 4) * &H8))
Next
Debug.Print Hex(outflags)
Edited to add:
this will only work for upto 8 tables, i.e. 4*8=32bits which is the size of a long

>> Edited by ben789 on Friday 16th January 17:08
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff