473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using Select Case in Constructor of a Class

I have just started to use Classes a lot in my code. Often I find that I
need to use the same contstructor, but wish to invoke a different action
depending on where I am clling the class from. I hav therefors started
sending an extra parameter to initialise the Class that I tend to call
sArea. I then use this in my code with a series of Select Statements in the
constructor, so that I can use the same constructor for parameters, but
carry out different actions depending on the case statement.

Is this an acceptable way of doing this or should I be looking at doing
something different??

Best wishes

Paul Bromley
Nov 20 '05 #1
3 1226
* "Paul Bromley" <fl*******@dsl.pipex.com> scripsit:
I have just started to use Classes a lot in my code. Often I find that I
need to use the same contstructor, but wish to invoke a different action
depending on where I am clling the class from. I hav therefors started
sending an extra parameter to initialise the Class that I tend to call
sArea. I then use this in my code with a series of Select Statements in the
constructor, so that I can use the same constructor for parameters, but
carry out different actions depending on the case statement.


I am not sure if I understand your problem. You can implement the
constructor with the 'Select Case' in a base class and then call the
base class' ctor from within inherited classes:

\\\
Public Class TheBaseClass
Public Sub New(ByVal Number As Integer)
Select Case Number
...
End Select
End Sub
End Class

Public Class Foo
Inherits TheBaseClass

Public Sub New(ByVal Number As Integer)
MyBase.New(Number)
End Sub
End Class
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Paul,
In addition to Herfried's response.

Should you be considering different classes?

Public Class BaseClass

Public Sub New()
' common construction
End Sub

End Class

Public Class Case1Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 1 specific construction
End Sub

End Class

Public Class Case2Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 2 specific construction
End Sub

End Class

Public Class Case1Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 3 specific construction
End Sub

End Class

With creating derived classes you can have methods & fields that are
specific to each derived class.

Hope this helps
Jay

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have just started to use Classes a lot in my code. Often I find that I
need to use the same contstructor, but wish to invoke a different action
depending on where I am clling the class from. I hav therefors started
sending an extra parameter to initialise the Class that I tend to call
sArea. I then use this in my code with a series of Select Statements in the constructor, so that I can use the same constructor for parameters, but
carry out different actions depending on the case statement.

Is this an acceptable way of doing this or should I be looking at doing
something different??

Best wishes

Paul Bromley

Nov 20 '05 #3
Hi Jay,

I suppose that I should.

Thanks for your repsonse & that of Herfried

Best wishes

Paul Bromley

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OO*************@TK2MSFTNGP10.phx.gbl...
Paul,
In addition to Herfried's response.

Should you be considering different classes?

Public Class BaseClass

Public Sub New()
' common construction
End Sub

End Class

Public Class Case1Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 1 specific construction
End Sub

End Class

Public Class Case2Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 2 specific construction
End Sub

End Class

Public Class Case1Class
Inherits BaseClass

Public Sub New()
MyBase.New()
' Case 3 specific construction
End Sub

End Class

With creating derived classes you can have methods & fields that are
specific to each derived class.

Hope this helps
Jay

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have just started to use Classes a lot in my code. Often I find that I
need to use the same contstructor, but wish to invoke a different action
depending on where I am clling the class from. I hav therefors started
sending an extra parameter to initialise the Class that I tend to call
sArea. I then use this in my code with a series of Select Statements in

the
constructor, so that I can use the same constructor for parameters, but
carry out different actions depending on the case statement.

Is this an acceptable way of doing this or should I be looking at doing
something different??

Best wishes

Paul Bromley


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
I traced the problem to what I believe is when I use the included content library script into the viewinterns.php page. This script will repeatedly instantiate a DateGroupHTMLGenerator class...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
10
by: Tony Johansson | last post by:
Hello Experts!! This class template and main works perfectly fine. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter in...
5
by: Colin Anderson | last post by:
I discovered, with great excitement, this article http://www.davison.uk.net/vb2notes.asp when researching methods for emailing from Access via Notes. Unfortunatly, when I run this I get a...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.