Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer)
InitializeCompo nent()
'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)
InitializeCompo nent()
'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 1149
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.goog le.com... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeCompo nent() '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) InitializeCompo nent() '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.goog le.com... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeCompo nent() '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) InitializeCompo nent() '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%******** *******@tk2msft ngp13.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.goog le.com... Hi, I have a class with lots of constructors - one is shown below
Public Sub New(ByVal rows As Integer, ByVal columns As Integer) InitializeCompo nent() '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) InitializeCompo nent() '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 conflict with one
another." I've run the same stored procedure with the same exact list of
arguments in Query Analyser in SQL Server, and it works. The page has the
adovbs constants. Note that uspGetProperties is a stored procedure in SQL...
|
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 Event log.
My environment:
Windows Server 2003, IIS 6, WSH, Classic ASP, Vbscript
Below is the code and the error:
Code:
|
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 thiscall), and what
parameters it expects? I know all about the argument ordering on the stack,
but I don't really know enough ASM to work with it. Does anyone out there
know of a cheap way to do it in more standardized C++? (efficiency doesn't...
|
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)
modHandler.rptOpen (Me.Report.Name), (Me.Tag)
End Sub
|
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 called
MyFunction. Can you specify a string for the function name like you
can with the form name? That is can I do something like
Forms("MyForm")."MyFunction"
| |
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 from a user's
program and use a C backend to evaluate the tree. I'm using Lex, Yacc
and C. Now, there are some functions that are built into this language
and others which are not. The problem I'm having is that I haven't
found a way to represent...
|
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 like the below
and have no idea what to do with it :)
inheritedClass::inheritedClass ()
: originalConstructor ()
, m_cells(cells), m_srfcs(srfcs)
{
|
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 syntax to be able to programmatically have my
imgSubmitSearch button clicked? I tried the obvious, Call imgSubmitSearch,
but intellisense doesn't like that due to the sender / e arguments.
Private Sub imgSubmitSearch_Click(ByVal sender As...
|
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 (confirmation) declared in page.
Dim RsSp , SQLSp
Set RsSp = Server.CreateObject("ADODB.Recordset")
SQLSp = "Declare @confirm varchar(1)"
SQLSp = SQLSp & "Exec SendMsg_proc "& "'" & UniCode &"' , '" & DintUserId &"' , '" & DintOrg_id &"' ,...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |