Don't understand error

B

Bryan Dickerson

The error is "Statement is not valid in a Namespace" and the code segment
that it points to is:
------------------------------------------------------------------
Option Strict Off
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

#Region " Web Services Designer Generated Code "

Public Sub New()
MyBase.New()

'This call is required by the Web Services Designer.
InitializeComponent()

'Add your own initialization code after the InitializeComponent() call

End Sub
 
A

Alex Clark

Hi Bryan,
You need to define a class, observe:

Option Strict Off
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

Public Class MyClass ' ********* <-- START OF CLASS DEFINITION
#Region " Web Services Designer Generated Code "

Public Sub New()
MyBase.New()

'This call is required by the Web Services Designer.
InitializeComponent()

'Add your own initialization code after the InitializeComponent()
call

End Sub
--------------------------------------------------------

End Class ' ********* <-- END OF CLASS DEFINITION


Regards,
Alex Clark
 
B

Bryan Dickerson

A light just came on. I was doing a lot of cutting and pasting and so I
just had the "Designer Generated Code" outside of the class definition.
Another question: There is a "Public Sub New" in the "Designer Generated
Code". I know I can modify it, but is it "better" to have my own "Overrides
Public New" or modify the existing one and add my own extra code?

Thanx for your help!
 
C

Chris

Bryan said:
A light just came on. I was doing a lot of cutting and pasting and so I
just had the "Designer Generated Code" outside of the class definition.
Another question: There is a "Public Sub New" in the "Designer Generated
Code". I know I can modify it, but is it "better" to have my own "Overrides
Public New" or modify the existing one and add my own extra code?

Thanx for your help!

That really depends on what you want to do in your own sub new. If you
just want to do some extra coding when the Sub New fires, then just make
an init function and call it where it says "Add your own initialization
code after the InitializeComponent()" There is nothing wrong with that.
If you want to pass in some parameters, then you need to make your own
sub new.

Chris
 
T

tomb

Bryan said:
The error is "Statement is not valid in a Namespace" and the code segment
that it points to is:
------------------------------------------------------------------
Option Strict Off
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Right here, you need to declare a class object, such as:
Public MyClass

Without that, you can't have Sub New()

T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top