473,404 Members | 2,137 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,404 software developers and data experts.

Option Strict On does not cause compilation error

I have set Option Strict On
I also have Enum AssemblyLineStatus As Integer
My question is how come there is no compilation error when I compile
following code?

If CInt(ddlStatus.SelectedItem.Value) = AssemblyLineStatus.Client Then
' do whatever
End If

Shouldn't this cause a compilation error? I know in C#, you have to
explicitly either convert enumation to int or int to enumuation.

Just curious.
Thanks
May 8 '06 #1
2 1314

Justin wrote:
I have set Option Strict On
I also have Enum AssemblyLineStatus As Integer
My question is how come there is no compilation error when I compile
following code?

If CInt(ddlStatus.SelectedItem.Value) = AssemblyLineStatus.Client Then
' do whatever
End If

Shouldn't this cause a compilation error? I know in C#, you have to
explicitly either convert enumation to int or int to enumuation.


VB is different, and less strict here. In VB, **a widening conversion
(essentially, one guaranteed not to lose information) can always occur
implicitly**. Conversion from an enum value to the enum's underlying
type is obviously widening, so in the above code,
AssemblyLineStatus.Client gets widened to its Integer value.

In C#, on the other hand, there is no such general rule of implicitness
for widening conversions, and the set of implicit conversions is hence
much smaller. All conversions between enum types and numeric types -
even an enum's underlying type - must be explicit.

VB.NET is stricter than VB6, but it still isn't as strict as C#.

--
Larry Lard
Replies to group please

May 8 '06 #2
Justin wrote:
I have set Option Strict On
Good Start ...
I also have Enum AssemblyLineStatus As Integer .... If CInt(ddlStatus.SelectedItem.Value) = AssemblyLineStatus.Client Then
' do whatever
End If

Shouldn't this cause a compilation error?
CInt() returns an Integer and all Enums are defined as Integer.
I suspect VB sees Enum-to-Integer as a Widening Conversion, much like
Short-to-Integer.
I know in C#, you have to explicitly either convert


If you want to do the comparsion "as" the Enumeration, try this

' Throws ArgumentException (IIRC) for invalid values
Dim eValue as AssemblyLineStatus _
= CType(ddlStatus.SelectedItem.Value _
, AssemblyLineStatus)

If eValue = AssemblyLineStatus.Client Then
' do whatever
End If

HTH,
Phill W.
May 8 '06 #3

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

Similar topics

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...
30
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...
6
by: Brett | last post by:
I find there is more casting required in C# than VB.NET. If Option Strict/Explicit is turned on, will this basically create the same environment as C# - uppercase, more casting required, must...
7
by: Owen Mortensen | last post by:
(This code was working in asp.net 1.1 VS2003. After upgrade to VS2005, chokes): in the aspx file: <ItemTemplate> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"...
1
by: Adotek | last post by:
Hi All, I've just converted a solution from .Net v1.1 to v2.0, by allowing Visual Studio 2005 to do the conversion. Since doing so, I am getting a compilation error as follows: "Option...
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"...
0
by: Michael Jenck | last post by:
Hi All, I have been playing with the codedom and can't get it to output for option compare Binary with a CodeCompileUnit. I have searched the web and Don't now if it's possible. If it's not...
18
by: Poldie | last post by:
How do I turn it on? I'm using vb 2005 in visual studio 2005 sp1. In my web.config I have: <compilation debug="true" strict="true" /> In my Tools/Options/Projects and solutions/vb defaults...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.