Results 1 to 3 of 3

Thread: [RESOLVED] Option strict implicit/disallow errors on a simple form

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Resolved [RESOLVED] Option strict implicit/disallow errors on a simple form

    Hi, This is an only gif player form which does it once. (Sort of splash form)
    Here's the code:
    Code:
    Public NotInheritable Class SplashScreen
        Protected Overrides ReadOnly Property CreateParams As CreateParams
            Get
                CreateParams = MyBase.CreateParams
                CreateParams.ExStyle = CreateParams.ExStyle Or &H2000000
                Return CreateParams
            End Get
        End Property
    
        Dim animatedImage = My.Resources.splash '*
        Dim currentlyAnimating As Boolean = False
        Dim framecounter As Integer = 0
        Dim framecount As Integer
        Dim framdim As Imaging.FrameDimension
        Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
            PictureBox1.Invalidate()
        End Sub
        Sub AnimateImage()
            If Not currentlyAnimating Then
                ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged)) '**
                currentlyAnimating = True
            End If
        End Sub
        Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
            If framecounter < framecount Then
                AnimateImage()
                ImageAnimator.UpdateFrames()
                e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0)) '***
                framecounter += 1
            Else
                Me.Hide()
                MainWindow.Show()
            End If
        End Sub
        Private Sub SplashScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Opacity = 0
            Me.Width = My.Resources.splash.Width
            Me.Height = My.Resources.splash.Height
            Me.TopMost = True
            framdim = New Imaging.FrameDimension(animatedImage.FrameDimensionsList(0)) '****
            framecount = animatedImage.GetFrameCount(framdim) '*****
        End Sub
    End Class
    In option strict = off it works fine, no errors. In option strict = on, following errors will occur:

    * Option Strict On requires all variable declarations to have an 'As' clause.
    ** Option Strict On disallows implicit conversions from 'Object' to 'Image'.
    *** Overload resolution failed because no accessible 'DrawImage' can be called with these arguments: (A list of 'image' and 'object's.)
    **** Option Strict On disallows late binding.
    ***** Option Strict On disallows late binding.
    Last edited by pourkascheff; Feb 12th, 2023 at 04:13 AM.

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

    Re: Option strict implicit/disallow errors on a simple form

    ALWAYS set Option Strict On at the project level. If you specifically need late binding then set it Off in the specific files where that's required. Even then, use partial classes to keep the code in those files to an absolute minimum.

    The issue appears to be that you have Option Infer Off. This line is the root of the issue:
    vb.net Code:
    1. Dim animatedImage = My.Resources.splash
    Whoever wrote that line was almost certainly assuming that the type of the animatedImage variable would be inferred from the type of the My.Resources.splash property, which requires Option Infer On. If it's On then the variable will have the same type as the property, which is presumably Image or Bitmap. With Option Infer Off, no type inference can occur, so you would need to either specify the type of the variable explicitly or else have it default to type Object. The latter will happen if you have Option Strict Off and don't specify the type but Option Strict On REQUIRES that you specify the type explicitly.

    Basically, you need to decide whether you're going to set Option Infer On or Off. You don't need it On in most cases so you can turn it Off, but then you need to specify the type of every variable explicitly. I suggest that you set Option Infer On and use type inference where it's appropriate.
    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
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Option strict implicit/disallow errors on a simple form

    Thanks for clear information jmcilhinney.
    The aforementioned error was rectified by adding 'as bitmap' to the line.

Tags for this Thread

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