VS2012 - Option Strict and Option Explicit don't always perform the same
I just ran into something weird. I always set my projects to Option Strict ON and Option Explicit ON.
I have a large project that has absolutely no problem with code similar to below. However, I just started a new project and now I get a build error that says "Option Strict On disallows implicit conversions from Double to Integer."
So my question is, with both projects set up the same, why does one allow this while the other will not?
vb.net Code:
Private Sub LoginFrm_Resize(sender As Object, e As EventArgs) Handles Me.Resize
Me.LoginPanel.Location = New Point((Me.Width - Me.LoginPanel.Width) / 2, _
(Me.Height - Me.LoginPanel.Height) / 2)
End Sub
Re: VS2012 - Option Strict and Option Explicit don't always perform the same
I'm guessing that you're mistaken and the project that is not throwing the error actually has different code. The issue there is the division operator (/). That operator is going to return a Double and obviously has to. If you divide an odd number by 2 then the result will end with '.5', which obviously isn't an Integer. If you want to make that work then you have to use the integer division operator (\) instead. That will return an Integer and truncate the result of the division to the nearest whole number.
Re: VS2012 - Option Strict and Option Explicit don't always perform the same
I actually copied that exact event from the original project to the new one, so the exact same code is in both projects.
Thanks for catching the division operator, I overlooked that completely!
2 Attachment(s)
Re: VS2012 - Option Strict and Option Explicit don't always perform the same
Original Project:
Attachment 98491
New Project:
Attachment 98493
Re: VS2012 - Option Strict and Option Explicit don't always perform the same
If Option Strict is On for that first project and for that file then I have no explanation for that.
Re: VS2012 - Option Strict and Option Explicit don't always perform the same
I can't explain it either. Now I'm concerned what else it is letting me get away with in the original project, which is quite large.