By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,731 Members | 840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,731 IT Pros & Developers. It's quick & easy.

Using Select Case in Constructor of a Class

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
* "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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.