[Gambas-user] Weird, yet again. Two way access to a collection. (not really a gambas issue)

Christof Thalhofer chrisml at deganius.de
Wed Nov 21 11:10:45 CET 2018


Am 21.11.18 um 09:54 schrieb Bruce:

> (EXAMPLE) Let's say we have an Ice Cream Parlor POS application that is 
> loosely connected to the inventory "system". If a situation occurs where 
> there is no chocolate ice cream in stock then, when the POS operator 
> presses key 4617 (a chocolate ice cream) then it would display 
> "Chocolate Ice Creams are out of stock today, offer another flavor". So, 
> code 1329 = that explanation, but when I'm coding I'd like to specify 
> the status as "NO_CHOC" rather than go search through a bunch of design 
> documents and other stuff to find the right status code to use.  I hope 
> that makes sense, it's the simplest explanation I can think of. By the 
> way, in reality we have around 1600 specific status codes in our 
> systems. So I am really hoping that someone has a good idea here.

Does the example describe a real situation? I mean, if the status
represents the (non-)existence of a product in stock it is another thing
as if the status represents the state of the code at runtime.

The first I would never handle by hardcoded status codes because once
you invent a new product the software would have to be rewritten. That
would be crazy in case of icecream.

If the state of the software at runtime should be represented there are
many possible solutions. For instance I could think about a combination
of a bitmap together with integer constants.

A bitmap is like that

0000101000101 ...

and can easily been stored in a string.

With constants you can set named positions in the bitmap, for example in
a module named State:

Public Constant MachineRunnning as Integer = 1
Public Constant OperatorFired as Integer = 2
...
Public Constant MachineIsDirty as Integer = 5
Public Constant OperatorDead as Integer = 6

In the Bitmap up there MachineIsDirty is set true and the operator lives ;-)

By writing code you now are able to write sth like:

State.Set(State.MachineIsDirty)

or

bMachineDirty = State.Get(State.MachineIsDirty)

As long as State.Set and State.Get translate the boolean value to
bit-position and vice versa.

If you are interested, I dig the code for that (set and get values out
of bitmaps) out of my libs.



Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181121/b2d625bd/attachment.sig>


More information about the User mailing list