Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:51:40+00:00 2026-05-19T04:51:40+00:00

I am currently trying to use a bit flag enum in a VB6 /

  • 0

I am currently trying to use a bit flag enum in a VB6 / COM project.
However, when trying to read values from the enum, I get inconsistent results.

Here is the enum definition :

Enum Fruits
    None = 0
    Apple = 1
    Strawberry = 2
    Lemon = 4
End Enum

I have an object which exposes a property of type Fruits

Public Get AvailableFruits as Fruits

The code that should be able to read the value is used to show / hide a label depending on the values of each bit of the enum :

lblAppleAvailable.Visible = basket.AvailableFruits And Fruits.Apple

When this code is executed and I have basket.AvailableFruits = 0, I get True as result.

Any idea of what could cause this behavior ?

Edit :

I have tried with the different values of the enum :

basket.AvailableFruits = 0
basket.AvailableFruits And Apple        // Returns True
basket.AvailableFruits And Strawberry   // Returns True
basket.AvailableFruits And Lemon        // Returns False

As a side node, when debugging the code, If I put the expression in a watch expression, I get the correct value; but when the expression is evaluated in my code, it still returns True.

I tried using a different check syntax :

(basket.AvailableFruits And Fruits.Apple) = Fruits.Apple

Still getting True when basket.AvailableFruits = 0 🙁

Solution

After having tested different solutions, I have been able to narrow the problem to the COM component.
The original coder of this component had a pointer set to 0 instead of returning 0 as a value, which caused the problem when trying to read the value.

I have selected FlipScript answer because of the helper function which seems a good tip to improve the readability of the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:51:41+00:00Added an answer on May 19, 2026 at 4:51 am

    To test the value of the flag, use something like this:

    lblAppleAvailable.Visible = (basket.AvailableFruits And Fruits.Apple) = Fruits.Apple
    

    After you do the “AND”, you still need to see if the resulting value equals the flag value (or anything other than 0, really).

    You could also create a little helper function:

    Private Function HasFruitFlag(Check As Fruits, Flag As Fruits) As Boolean
        HasFruitFlag (Check And Flag) = Flag
    End Function
    

    And you could call it like this:

    lblAppleAvailable.Visible = HasFruitFlag(basket.AvailableFruits, Fruits.Apple)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first a little bit of documentation from the jQuery validation plugin: Use submitHandler to
Perhaps this is a stupid question, but I'm trying to use BGL's dijkstra_shortest_paths ,
I'm trying to learn Haskell by writing little programs... so I'm currently writing a
I'm trying to use decorators in order to manage the way users may or
The title is a bit confusing...I'll explain I have an NSMutableArray I am populating
I know that I can use the terminal and the system-profiler command to determine
Having a bit of an issue please see the following code: window.onload = function
Guys i'm really embaraced to ask for this, but i got stuck and i
I've posted a couple other questions during this process, but I have a better
I wonder if someone can help me... I've been developing VB.Net for years and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.