473,385 Members | 1,927 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,385 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 1181

"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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.