Storing multiple setting values in an Integer 
Author Message
 Storing multiple setting values in an Integer

I like the idea of storing multiple settings values within an integer
located within the registry, e.g.:

ImageType=31

Where these are the values for image types:

GIF=1
TIFF=2
PNG=4
GIF=8
BMP=16

If all image types are turned on then the max value for the ImageType value
would be 31.

Now, if I was going to query this value to determine whether GIF is enabled
it seems to me I would have to first determine BMP, GIF, PNG & TIFF --in
that order-- before I could determine whether or not GIF was indeed enabled.
Is that the conclusion others have as well?

Would a better way be to store the information in binary format? Perhaps if
it was one could "AND"" the value to determine whether or not GIF was turned
on without the need to query the other values first?

For example:

vData = 1F

If (vData And H1&) = H1& Then DoSomething

Would that work better, or at all?

BB



Wed, 06 Jul 2005 05:08:51 GMT  
 Storing multiple setting values in an Integer

Quote:
> I like the idea of storing multiple settings values within an
integer
> located within the registry, e.g.:

> ImageType=31

> Where these are the values for image types:

> GIF=1
> TIFF=2
> PNG=4
> GIF=8
> BMP=16

> If all image types are turned on then the max value for the
ImageType value
> would be 31.

> Now, if I was going to query this value to determine whether GIF is
enabled
> it seems to me I would have to first determine BMP, GIF, PNG &
TIFF --in
> that order-- before I could determine whether or not GIF was indeed
enabled.
> Is that the conclusion others have as well?

> Would a better way be to store the information in binary format?
Perhaps if
> it was one could "AND"" the value to determine whether or not GIF
was turned
> on without the need to query the other values first?

> For example:

> vData = 1F

> If (vData And H1&) = H1& Then DoSomething

> Would that work better, or at all?

> BB

You don't have to use hex to use the bitwise operators.

Const GIF=1
Const TIFF=2
Const PNG=4
Const GIF=8
Const BMP=16
vData = vData Or GIF    'sets the GIF bit
If (vData And GIF) = GIF Then (the gif bit is set)
'or put another way...
If CBool(vData And GIF) Then (the gif bit is set)

etc...

HTH-Jon



Wed, 06 Jul 2005 05:21:58 GMT  
 Storing multiple setting values in an Integer

Quote:

>I like the idea of storing multiple settings values within an integer
>located within the registry, e.g.:

>ImageType=31

>Where these are the values for image types:

>GIF=1
>TIFF=2
>PNG=4
>GIF=8
>BMP=16

>If all image types are turned on then the max value for the ImageType value
>would be 31.

>Now, if I was going to query this value to determine whether GIF is enabled
>it seems to me I would have to first determine BMP, GIF, PNG & TIFF --in
>that order-- before I could determine whether or not GIF was indeed enabled.
>Is that the conclusion others have as well?

>Would a better way be to store the information in binary format? Perhaps if
>it was one could "AND"" the value to determine whether or not GIF was turned
>on without the need to query the other values first?

Storing values in binary format makes it nice for reading values directly but it's not really needed to go though all the hoops to do it...
Integer 31(hex 1F) in binary is 11111 (internally)
using the following will check its bits are set or not...

ImageType and &h01 'This would check GIF
ImageType and &h02 'TIFF
ImageType and &h04 'PNG
ImageType and &h08 'GIF (double??)
ImageType and &h10 'BMP

If only PNG has been set then ImageType would equal 00100 binary..
if only the second GIF and TIFF are set it would be 01010 binary
so if you do this: ImageType AND &h02 will be true if TIFF has been
added to the mix...

HTH,, and I didn't make any mistRakes.. LOL

Quote:
>For example:

>vData = 1F

>If (vData And H1&) = H1& Then DoSomething

>Would that work better, or at all?

>BB

Have a good day...

Don



Wed, 06 Jul 2005 05:39:23 GMT  
 Storing multiple setting values in an Integer

Quote:
> I like the idea of storing multiple settings values within an integer
> located within the registry, e.g.:

> ImageType=31

> Where these are the values for image types:

> GIF=1
> TIFF=2
> PNG=4
> GIF=8
> BMP=16

> If all image types are turned on then the max value for the ImageType
value
> would be 31.

> Now, if I was going to query this value to determine whether GIF is
enabled
> it seems to me I would have to first determine BMP, GIF, PNG & TIFF --in
> that order-- before I could determine whether or not GIF was indeed
enabled.
> Is that the conclusion others have as well?

> Would a better way be to store the information in binary format? Perhaps
if
> it was one could "AND"" the value to determine whether or not GIF was
turned
> on without the need to query the other values first?

> For example:

> vData = 1F

> If (vData And H1&) = H1& Then DoSomething

> Would that work better, or at all?

In these cases I prefer to use an enumerator, particularly when exporting it
as a property of the class:

'***
Public Enum enImgType
    itGIF = &H1
    itTIFF = &H2
    itPNG = &H4
    itGIF = &H8
    itBMP = &H10
End Enum

' Check to see if a specific format is supported
Public Function CheckFormat(ByVal inFormat As Long, _
    ByVal inCheck as enImgType) As Boolean
    CheckFormat = (inFormat And inCheck) <> 0
End Function

' Add a specific format to a format list
Public Function AddFormat(ByVal inFormat As Long, _
    ByVal inAdd As enImgType) As Long
    AddFormat = (inFormat Or inAdd)
End Function

' Remove a specific format from a format list
Public Function RemoveFormat(ByVal inFormat As Long, _
    ByVal inRemove As enImgType) As Long
    RemoveFormat = (inFormat And (Not inRemove))
End Function
'***

Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 06 Jul 2005 05:41:51 GMT  
 Storing multiple setting values in an Integer

Quote:

> I like the idea of storing multiple settings values within an integer
> located within the registry, e.g.:

> ImageType=31

> Where these are the values for image types:

I would use the "And" option, storing the required values in a Long:

Private Enum TypesEnum

    GIF=1
    TIFF=2
    PNG=4
    GIF=8
    BMP=16

End Enum

vData = &H1F

If (vData And TypesEnum.GIF) <> 0 Then DoSomethingWithGIF

What intrigues me is why you would want more than one of these values
in vData (or your registry entry) at a time.

<LOL> My spelling checker just suggested that "Enum" should be
"Enema">

Gale.



Wed, 06 Jul 2005 05:45:14 GMT  
 Storing multiple setting values in an Integer
On Fri, 17 Jan 2003 21:45:14 +0000, Gale Green

I just noticed, you've got GIF twice. Don't do that in the real app.
<g>

Quote:
>     GIF=1
>     TIFF=2
>     PNG=4
>     GIF=8
>     BMP=16

Gale.


Wed, 06 Jul 2005 05:56:22 GMT  
 Storing multiple setting values in an Integer
Thank you, and to the others as well, for your respones.

I tried your example but could not get it to work as expected. For example:

    Public Const JPEG = 1
    Public Const TIFF = 2
    Public Const PNG = 3
    Public Const GIF = 8
    Public Const BMP = 16

Public Function mP_IsMediaTypeSet(iMediaType As Integer, sKey As String) As
Boolean

    iMediaType% = JPEG    'MediaType being checked. I have passed the Const
JPEG to this function

    Dim iValue As Integer

    iValue% = 16  'This would represent ONLY the BMP value as being set.
Let's say I pulled this from registry

    iValue% = iValue% Or iMediaType%

    mP_IsMediaTypeSet = (iValue% And iMediaType% = iMediaType%)

End Function

The function always returns True. Shouldn't it return False since the value
of iValue% = 16 representing only a BMP value. What am I missing here? I
also tried it by commenting out this line:

 'iValue% = iValue% Or iMediaType%

It seemed from the other posts this wasn't neccessary. Either way, it always
returns True.

BB



Quote:


> > I like the idea of storing multiple settings values within an
> integer
> > located within the registry, e.g.:

> > ImageType=31

> > Where these are the values for image types:

> > GIF=1
> > TIFF=2
> > PNG=4
> > GIF=8
> > BMP=16

> > If all image types are turned on then the max value for the
> ImageType value
> > would be 31.

> > Now, if I was going to query this value to determine whether GIF is
> enabled
> > it seems to me I would have to first determine BMP, GIF, PNG &
> TIFF --in
> > that order-- before I could determine whether or not GIF was indeed
> enabled.
> > Is that the conclusion others have as well?

> > Would a better way be to store the information in binary format?
> Perhaps if
> > it was one could "AND"" the value to determine whether or not GIF
> was turned
> > on without the need to query the other values first?

> > For example:

> > vData = 1F

> > If (vData And H1&) = H1& Then DoSomething

> > Would that work better, or at all?

> > BB

> You don't have to use hex to use the bitwise operators.

> Const GIF=1
> Const TIFF=2
> Const PNG=4
> Const GIF=8
> Const BMP=16
> vData = vData Or GIF    'sets the GIF bit
> If (vData And GIF) = GIF Then (the gif bit is set)
> 'or put another way...
> If CBool(vData And GIF) Then (the gif bit is set)

> etc...

> HTH-Jon



Wed, 06 Jul 2005 06:34:51 GMT  
 Storing multiple setting values in an Integer

Quote:

>Thank you, and to the others as well, for your respones.

>I tried your example but could not get it to work as expected. For example:

>    Public Const JPEG = 1
>    Public Const TIFF = 2
>    Public Const PNG = 3

This should be 4.  Raising to the power of two etc...

Quote:
>    mP_IsMediaTypeSet = (iValue% And iMediaType% = iMediaType%)

Operator precedence. Note the extra pair of brackets.
 mP_IsMediaTypeSet = ((iValue% And iMediaType%) = iMediaType%)

--

Regards, Frank



Wed, 06 Jul 2005 07:36:32 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. How to store / retrieve a stored (hidden) value from a combo box in Visual Basic 6

2. How to pass single, multiple or null parameter value(s) to multiple queries

3. Return value and Output values from Stored Procedure

4. Storing a 64Bits integer as a type compatible with MSAccess, but not string

5. Store 2 integers in a long?

6. How to store integer array

7. Store 2 integers in a long?

8. How to pass an integer array/userdef type array into an Oracle Stored procedure

9. Store 2 integers in a long?

10. restricting values of integers in code

11. Pass integer Value from forms Class mod to report class mod

12. integer values for fields

 

 
Powered by phpBB® Forum Software