Results 1 to 6 of 6

Thread: VS2012 - Option Strict and Option Explicit don't always perform the same

  1. #1

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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:
    1. Private Sub LoginFrm_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    2.         Me.LoginPanel.Location = New Point((Me.Width - Me.LoginPanel.Width) / 2, _
    3.                                            (Me.Height - Me.LoginPanel.Height) / 2)
    4. End Sub
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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!
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  4. #4

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: VS2012 - Option Strict and Option Explicit don't always perform the same

    Original Project:

    Name:  Capture.PNG
Views: 239
Size:  7.8 KB


    New Project:

    Name:  Capture1.PNG
Views: 239
Size:  8.6 KB
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width