Flags64 Class - Storing 64 flags in one Int64

I’ve saw people needing it. So, I’ll share my contribution.

https://drive.google.com/file/d/11BONZm6RdB-Lf3K5icbbFLemZxILM4MK/view?usp=sharing

It enables you to write easily, things like, registering options, statuses, checkboxes, etc; in a simple packed form, usable in any database backends (as all them supports Integers):

[code]Dim i As Int64 = getIntegerFlagsFromDatabase()
Dim f As New Flags64(i)

If not f.Flag(12) Then // Something still not done!

ProcessThatThingMissing()
f.Flag(12, True) // Set it done

f.Flag(18, CheckBox1.Value) // Also stores the value of the Checkbox1

End

SaveFlagstoDatabase(f.Flags())
[/code]

That takes me back to writing adventure games on the BBC Model B
Each bit was an attribute of an object
Takeable
Eatable
Wearable
Light Source
Weapon
… etc

Really packed them in!

and that computer had to make as much use of limited resources as it could… a few bytes could mean the difference between a running program and an “out of memory” condition. And almost all variable space was pre-allocated, with the exception of the “stack”

not to mention that computer had no idea was a 64bit integer was :slight_smile: [or even a 32bit one]

Updated. Version 2.0 now supports named flags, letting code more readable and maintainable.

https://drive.google.com/open?id=11BONZm6RdB-Lf3K5icbbFLemZxILM4MK

New:

[code]f.Flag(n, “my flag name”) // set a name for flag n

f.Flag(“my flag name”, true|false) // sets a named flag to true or false

f.Flag(“my flag name”) // returns the named flag value (true or false)
[/code]

Uses:

If flagSet1.Flag("Is Printable") Then // flagSet1 contains more than a dozen flags PrintThat() flagSet1.Flag("Printed", True) // Store that we already printed it at least once End flagSet2.Flag("Polimorphic", True) // Set "polimorphic" to True in the Int64 flagSet2