variable declaration errors in VS 2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code and I don't understand why I get a "Declaration
expected" error for the myPen and formGraphics variables.

Imports System.Drawing

Public Class ucInfield
Dim myPen As New Pen(System.Drawing.Color.Red)
Dim formGraphics As Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
myPen.Dispose()
formGraphics.Dispose()
End Class

In the last four lines, Intellisense shows them with squiggly lines and the
project won't compile. Any help would be appreciated.

Regards,
Mark
 
The need to be inside a method, not at class level.

Public Class ucInfield
Dim myPen As New Pen(System.Drawing.Color.Red)
Dim formGraphics As Graphics

Public Sub FooBar()
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
myPen.Dispose()
formGraphics.Dispose()
End Sub

End Class

Greg
 
Thanks for your help.

Greg Burns said:
The need to be inside a method, not at class level.

Public Class ucInfield
Dim myPen As New Pen(System.Drawing.Color.Red)
Dim formGraphics As Graphics

Public Sub FooBar()
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
myPen.Dispose()
formGraphics.Dispose()
End Sub

End Class

Greg
 
Back
Top