1 Attachment(s)
Option Strict On causing error
Hi All.. when I use Option Strict On with this code, I get errors. Can someone please tell me what is wrong with this code?
Code:
Dim dynamicButton As New Button
dynamicButton.Location = New Point(Me.PictureBox2.PointToClient(MousePosition))
The error shows on the 'Point' in New Point. I am not sure how to fix that.
Re: Option Strict On causing error
You cannot call directly
Code:
dynamicButton.Location = New Point(Me.PictureBox2.PointToClient(MousePosition))
the New point method ask for coordinate or size type, not a point.
You can write :
Code:
dynamicButton.Location = Me.PictureBox2.PointToClient(MousePosition)
or
dynamicButton.Location = New Point(Me.PictureBox2.PointToClient(MousePosition).X,Me.PictureBox2.PointToClient(MousePosition).Y)
Re: Option Strict On causing error
Thanks Delaney, this does the trick.
Re: Option Strict On causing error
Option Strict on does not cause an error... It reveals your error :D
Re: Option Strict On causing error
Quote:
Originally Posted by
.paul.
Option Strict on does not cause an error... It reveals your error :D
Indeed. The error here was that you were trying to create a new Point when you didn't need to. PointToClient returns a Point so why would you need to create a new one at all? Think of all the junky code like this that you might write without it being picked up by the compiler when you have Option Strict Off? In such cases, the system makes a best guess at what you were actually trying to achieve. On many occasions, it will guess correctly. On those that it doesn't get it right, your application will quite possibly just continue chugging along and using the wrong data. That's why you should ALWAYS have Option Strict On and learn how to write good code.