473,382 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Option Strict - Bit Enumerations

Option Strict On

Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum

<STAThread()> _
Public Sub Main()
Dim bits As MyBitFields = MyBitFields.MyValue1 + MyBitFields.MyValue2
End Sub
The above code doesn't work because the Option Strict'ness doesn't allow the
conversion from integer to enumeration? Can someone help me with this?
Option Strict is required and I don't control the enumeration. I am
Implementing the IDTCommandTarget interface and the parameter StatusOption
(EnvDTE.vsCommandStatus enumeration) is byref. I need to set this ref value
to vsCommandStatus.vsCommandStatusEnabled +
vsCommandStatus.vsCommandStatusSupported.

By the way, by required I meant my own requirements. I can turn it off, but
why should I have to? Isn't there a way to get around this?

Any help would be appreciated....

Thank you,
Mythran
Nov 21 '05 #1
6 1180

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Option Strict On

Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum

<STAThread()> _
Public Sub Main()
Dim bits As MyBitFields = MyBitFields.MyValue1 + MyBitFields.MyValue2
End Sub
The above code doesn't work because the Option Strict'ness doesn't allow
the conversion from integer to enumeration? Can someone help me with
this? Option Strict is required and I don't control the enumeration. I am
Implementing the IDTCommandTarget interface and the parameter StatusOption
(EnvDTE.vsCommandStatus enumeration) is byref. I need to set this ref
value to vsCommandStatus.vsCommandStatusEnabled +
vsCommandStatus.vsCommandStatusSupported.

By the way, by required I meant my own requirements. I can turn it off,
but why should I have to? Isn't there a way to get around this?

Any help would be appreciated....

Thank you,
Mythran


CType works :)

Mythran
Nov 21 '05 #2

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Option Strict On

Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum

<STAThread()> _
Public Sub Main()
Dim bits As MyBitFields = MyBitFields.MyValue1 + MyBitFields.MyValue2
End Sub
The above code doesn't work because the Option Strict'ness doesn't allow
the conversion from integer to enumeration? Can someone help me with
this? Option Strict is required and I don't control the enumeration. I am
Implementing the IDTCommandTarget interface and the parameter StatusOption
(EnvDTE.vsCommandStatus enumeration) is byref. I need to set this ref
value to vsCommandStatus.vsCommandStatusEnabled +
vsCommandStatus.vsCommandStatusSupported.

By the way, by required I meant my own requirements. I can turn it off,
but why should I have to? Isn't there a way to get around this?

Any help would be appreciated....

Thank you,
Mythran


CType works :)

Mythran
Nov 21 '05 #3
Two things.

1. Use "Or" for bit combinations, not "+". Required with Option
Strict. Using CType to allow "+" is a hack.

2. Decorate the enum with the Flags attribute. Not required, but
encouraged.

HTH,

Sam

Option Strict On

Imports System

<Flags()> _
Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum

Module Test

Public Sub Main()
Dim bits As MyBitFields = MyBitFields.MyValue1 Or
MyBitFields.MyValue2
Console.WriteLine(bits.ToString())
End Sub

End Module
Nov 21 '05 #4
Two things.

1. Use "Or" for bit combinations, not "+". Required with Option
Strict. Using CType to allow "+" is a hack.

2. Decorate the enum with the Flags attribute. Not required, but
encouraged.

HTH,

Sam

Option Strict On

Imports System

<Flags()> _
Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum

Module Test

Public Sub Main()
Dim bits As MyBitFields = MyBitFields.MyValue1 Or
MyBitFields.MyValue2
Console.WriteLine(bits.ToString())
End Sub

End Module
Nov 21 '05 #5

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote
The above code doesn't work ...
Can someone help me with this?

<Flags()> _
Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum
Dim bits As MyBitFields = MyBitFields.MyValue1 Or MyBitFields.MyValue2
See FlagsAttribute in Help for more info.

LFS

Nov 21 '05 #6

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote
The above code doesn't work ...
Can someone help me with this?

<Flags()> _
Public Enum MyBitFields As Integer
MyValue1 = 1
MyValue2 = 2
MyValue3 = 4
MyValue4 = 8
End Enum
Dim bits As MyBitFields = MyBitFields.MyValue1 Or MyBitFields.MyValue2
See FlagsAttribute in Help for more info.

LFS

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
8
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a...
0
by: Mythran | last post by:
Option Strict On Public Enum MyBitFields As Integer MyValue1 = 1 MyValue2 = 2 MyValue3 = 4 MyValue4 = 8 End Enum <STAThread()> _
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
13
by: C. Moya | last post by:
I fully expected the lack of a way to set Option Strict globally to be fixed in SP1. I can't seem to figure out if it has been fixed or not. It still seems we have to add the declaration at the top...
1
by: Jerad Rose | last post by:
I believe this issue is specific to ASP.NET. Why does VB.NET (2.0) ignore the project-level setting for Option Strict? I have the setting turned on in web.config: <compilation debug="true"...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
8
by: =?Utf-8?B?R3JlZw==?= | last post by:
We have an application in our office that has the Option Strict option set to off right now. I do understand it should be set to ON, but right now, I'm just going to continue with it this way since...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.