Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer)
InitializeComponent()
'And code in here that sets instance variables,
'and does calculations based on rows and columns passed
'in in the constructor, and lots more.
End Sub
Another of my constructors has no parameters, and there are various
other
constructors that receive, for example, Point etc. But what I want to
do is
call one constructor New from another constructor New so I don't have
to reproduce the same code many times, or put it in a separate
procedure and call it from each New(..)
Here is what I am wanting to do, but the compiler is having none of it
!
Public Class test
Inherits System.Windows.Forms.Form
Public Sub New(ByVal rows As Integer, ByVal columns As Integer)
InitializeComponent()
'And code in here that sets instance variables,
'and does calculations based on rows and columns passed
'in in the constructor, and lots more.
End Sub
Public Sub New()
Dim defaultRows As Integer=2
Dim defaultColumns As Integer=10
Call New(defaultRows,defaultColumns)
End Sub
'More methods/code etc
End Class
Can someone cast their eye over this and help me along with the
correct syntax (the line "Call New(defaultRows,defaultColumns" is the
line the compiler balks at).
Thank you
Colin 4 1115
Colin, Can someone cast their eye over this and help me along with the correct syntax (the line "Call New(defaultRows,defaultColumns" is the line the compiler balks at).
Public Sub New()
MyClass.New(2, 10)
End Sub
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Colin,
In addition to Mattias example.
The call to MyClass.New or MyBase.New needs to be the first statement in the
constructor, before any other statements, or variable or constant
declarations.
Also you need to include the MyClass or MyBase so the compiler knows that
you are chaining to another constructor and that constructor is either in
the base class (MyBase) or the current class (MyClass).
And as Mattias showed, Call is optional hence I tend to omit it.
Hope this helps
Jay
"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab*************************@posting.google.co m... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Another of my constructors has no parameters, and there are various other constructors that receive, for example, Point etc. But what I want to do is call one constructor New from another constructor New so I don't have to reproduce the same code many times, or put it in a separate procedure and call it from each New(..)
Here is what I am wanting to do, but the compiler is having none of it !
Public Class test Inherits System.Windows.Forms.Form Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Public Sub New() Dim defaultRows As Integer=2 Dim defaultColumns As Integer=10 Call New(defaultRows,defaultColumns) End Sub
'More methods/code etc End Class
Can someone cast their eye over this and help me along with the correct syntax (the line "Call New(defaultRows,defaultColumns" is the line the compiler balks at).
Thank you Colin
You can also call Me.New(etc, etc)
--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab*************************@posting.google.co m... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Another of my constructors has no parameters, and there are various other constructors that receive, for example, Point etc. But what I want to do is call one constructor New from another constructor New so I don't have to reproduce the same code many times, or put it in a separate procedure and call it from each New(..)
Here is what I am wanting to do, but the compiler is having none of it !
Public Class test Inherits System.Windows.Forms.Form Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Public Sub New() Dim defaultRows As Integer=2 Dim defaultColumns As Integer=10 Call New(defaultRows,defaultColumns) End Sub
'More methods/code etc End Class
Can someone cast their eye over this and help me along with the correct syntax (the line "Call New(defaultRows,defaultColumns" is the line the compiler balks at).
Thank you Colin
Mike,
That's right! I was thinking there was a third syntax. Thanks for the
additional info.
I normally use either MyBase or MyClass in the constructor so I "forgot"
that Me was supported.
Thanks
Jay
"Mike Caputo" <mi************@radarwire.com> wrote in message
news:e%***************@tk2msftngp13.phx.gbl... You can also call Me.New(etc, etc)
--
Michael Caputo Programmer/Database Administrator Simon Economic Systems Ltd.
"Colin McGuire" <co***********@lycos.co.uk> wrote in message news:ab*************************@posting.google.co m... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Another of my constructors has no parameters, and there are various other constructors that receive, for example, Point etc. But what I want to do is call one constructor New from another constructor New so I don't have to reproduce the same code many times, or put it in a separate procedure and call it from each New(..)
Here is what I am wanting to do, but the compiler is having none of it !
Public Class test Inherits System.Windows.Forms.Form Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeComponent() 'And code in here that sets instance variables, 'and does calculations based on rows and columns passed 'in in the constructor, and lots more. End Sub
Public Sub New() Dim defaultRows As Integer=2 Dim defaultColumns As Integer=10 Call New(defaultRows,defaultColumns) End Sub
'More methods/code etc End Class
Can someone cast their eye over this and help me along with the correct syntax (the line "Call New(defaultRows,defaultColumns" is the line the compiler balks at).
Thank you Colin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dw |
last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a
connection. Every time I do, it generates an error "Arguments are of the
wrong type, are out of acceptable range, or are in...
|
by: Yitzhak |
last post by:
I am having "Permission denied" error while calling
LogEvent method of WScript.Shell component.
Basically, ASP page calls Windows Script Host Shell
component to log events to the OS Application...
|
by: Alex Lyman |
last post by:
Does anyone have any code handy (or know what a good direction for me to
head in), to call functions, if you have an address of the function, its
declspec (for my app, it's limited to _stdcall and...
|
by: deko |
last post by:
I'd like to use a bit of code in the OnOpen event of a report:
=rptOpen(Me.ReportName), (Me.Tag) --this doesn't work
This does work:
Private Sub Report_Open(Cancel As Integer)...
|
by: headware |
last post by:
I know that you can call the method of one from from inside another
form by doing something like this
Forms("MyForm").MyFunction(12, 34)
However, you have to know that MyForm has a function...
| |
by: Melkor Ainur |
last post by:
Hello,
I'm attempting to build an interpreter for a pascal-like language.
Currently, I don't generate any assembly. Instead, I just build an
abstract syntax tree representing what I've parsed...
|
by: lars.uffmann |
last post by:
I have to work on a rather big project that a bunch of people wrote and
that has no useful documentation at all, my C++ has rusted in a bit,
now I stumbled over a constructor that looks something...
|
by: Jason |
last post by:
I have an ASP.NET application in which I would like to call my button click
event (imgSubmitSearch_Click) on the page load if certain criteria are met.
Is this possible?
What is the correct...
|
by: Soniad |
last post by:
Hello,
I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |