472,811 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Constructors in Singleton Class

Forgive my ignorance on this one as I am trying to use a Singleton class. I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class have
a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor, but
getting an error with it. I have a feeling that I am not able to do this. Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley
Nov 21 '05 #1
14 2959
As usual, posting a question has made me think about a possible answer. I am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I assume
that this is permissible? I know that this is a stupid question, but I also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton
classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class have a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor, but getting an error with it. I have a feeling that I am not able to do this. Is there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley

Nov 21 '05 #2
Paul,

You can add properties to a singleton class just as you would to a regular
class.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
As usual, posting a question has made me think about a possible answer. I
am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I
assume
that this is permissible? I know that this is a stupid question, but I
also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton
classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
Forgive my ignorance on this one as I am trying to use a Singleton class.

I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class

have
a number of paramterised constructors enabling me to pass in parameters
or
not?

I am trying to use the following to send in a parmeter to a constructor,

but
getting an error with it. I have a feeling that I am not able to do this.

Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley


Nov 21 '05 #3
Thanks Mike.

Paul
"Mike McIntyre [MVP]" <mi****@getdotnetcode.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
Paul,

You can add properties to a singleton class just as you would to a regular
class.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
As usual, posting a question has made me think about a possible answer. I am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I
assume
that this is permissible? I know that this is a stupid question, but I
also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
Forgive my ignorance on this one as I am trying to use a Singleton class.
I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class

have
a number of paramterised constructors enabling me to pass in parameters
or
not?

I am trying to use the following to send in a parmeter to a
constructor, but
getting an error with it. I have a feeling that I am not able to do
this. Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default

property
Many thanks

Paul Bromley



Nov 21 '05 #4
The message you are getting is indicating that you are trying to pass an
argument where one is not expected. What is the "Create" method you have
there?
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
Forgive my ignorance on this one as I am trying to use a Singleton class.
I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class
have
a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor,
but
getting an error with it. I have a feeling that I am not able to do this.
Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley

Nov 21 '05 #5
Singletons work just as any other class with the exception that you can't
inherit from them.

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:O4*************@TK2MSFTNGP14.phx.gbl...
Thanks Mike.

Paul
"Mike McIntyre [MVP]" <mi****@getdotnetcode.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
Paul,

You can add properties to a singleton class just as you would to a
regular
class.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
> As usual, posting a question has made me think about a possible answer. I > am
> getting around the problem that I had below by accesing a property in
> my
> class and passing in parameters that are then used in my property. I
> assume
> that this is permissible? I know that this is a stupid question, but I
> also
> assume that I can have a number of properties in my singleton class as
> I
> would any other class - I have only seen very basic examples of Singleton > classes.
>
> Thanks
>
> Paul Bromley
>
>
> "Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
> news:uB**************@TK2MSFTNGP10.phx.gbl...
>> Forgive my ignorance on this one as I am trying to use a Singleton class. > I
>> need to use this to have one instance of my Class running and I think
>> I
>> understand how to do this. My question however is can a singleton
>> class
> have
>> a number of paramterised constructors enabling me to pass in
>> parameters
>> or
>> not?
>>
>> I am trying to use the following to send in a parmeter to a constructor, > but
>> getting an error with it. I have a feeling that I am not able to do this. > Is
>> there any other way that I can do this.
>>
>> Dim sPatName As String = "Green"
>> Dim EMP As CEmPacc = CEmPacc.Create(sPatName)
>>
>> Class myApp.CEmPacc cannot be indexed because it has no default property >>
>> Many thanks
>>
>> Paul Bromley
>>
>>
>
>



Nov 21 '05 #6
Paul,

"Paul Bromley" <fl*******@dsl.pipex.com> schrieb:
Forgive my ignorance on this one as I am trying to use a Singleton class.
I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class
have
a number of paramterised constructors enabling me to pass in parameters or
not?


Quick and dirty:

\\\
Public Class Singleton
Private m_UserName As String
Private m_Password As String

Private m_DefInstance As Singleton

Private Sub New()
'
End Sub

Private Sub New( _
ByVal UserName As String, _
ByVal Password As String _
)
m_UserName = UserName
m_Password = Password
End Sub

Public Function CreateInstance() As Singleton
If m_DefInstance Is Nothing Then
m_DefInstance = New Singleton
End If
Return m_DefInstance
End Function

Public Function CreateInstance( _
ByVal UserName As String, _
ByVal Password As String _
) As Singleton
If m_DefInstance Is Nothing Then
m_DefInstance = New Singleton(UserName, Password)
End If
Return m_DefInstance
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Errata:
Public Class Singleton


=> 'Public NotInheritable Class Singleton'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8
Many thanks Herfried, Scott & Mike,

I see exactly where I am going wrong now especially from the example that
Herfried has given - I was foolishly trying to send parameters to a Private
Sub New(), and I see quite obviously now that I need to send these to a
Public Function CreateInstance() As Singleton instead. I had not seen any
examples of using this type of class with parameters. Another stupid
question - I assume that I can place other initialisation code in this
function - i.e. calls to other Sub routines etc?

Again many thanks - as always I have learnt a lot - will try this later -
off to work now.

Best wishes

Paul Bromley


"Scott M." <s-***@nospam.nospam> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
The message you are getting is indicating that you are trying to pass an
argument where one is not expected. What is the "Create" method you have
there?
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
Forgive my ignorance on this one as I am trying to use a Singleton class. I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class
have
a number of paramterised constructors enabling me to pass in parameters or not?

I am trying to use the following to send in a parmeter to a constructor,
but
getting an error with it. I have a feeling that I am not able to do this. Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley


Nov 21 '05 #9
Paul,

"Paul Bromley" <fl*******@dsl.pipex.com> schrieb:
I see exactly where I am going wrong now especially from the example that
Herfried has given - I was foolishly trying to send parameters to a
Private
Sub New(), and I see quite obviously now that I need to send these to a
Public Function CreateInstance() As Singleton instead. I had not seen any
examples of using this type of class with parameters. Another stupid
question - I assume that I can place other initialisation code in this
function - i.e. calls to other Sub routines etc?


Yes, you can do that.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #10

Parameters in a Singleton depend entirely on the purpose of the
parameters. It may mean a singleton that needs initialization or you
could be talking about a different pattern--Flyweight.

If the parameters are intended to initialize the singleton and should
only be provided once, or should match if provided a second time, and
the singleton will still be a true singleton in that there will always
only be a single object whose reference won't be changed, then two
Instance properties should be implemented. One has no params and
returns the existing object only ifit has already been initialized
(throw error otherwise). The second accepts the params and if it's
the first call it initializes and returns the singleton. If it's a
subsequent call it should verify that the parameters match. See
ParameterizedSingleton below.

If the parameters are intended to represent a unique object where
there can be multiple instances of the object based on parameters but
all instances for the same parameters should be identical then the
object is not a Singleton but a Flyweight. In this case the shared
property is a collection of objects and not a single instance and is
indexed by one or both of the parameters. See Flyweight below.

HTH,

Sam
Public NotInheritable Class ParameterizedSingleton

Private _username As String
Private _password As String

Private Shared _instance As ParameterizedSingleton

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

' Singleton getters. Use Instance(username,password) first
' time to initialize the singleton and use Instance() on
' subsequent calls to use the existing singleton.

Public Shared ReadOnly Property Instance() As
ParameterizedSingleton
Get
If _instance Is Nothing Then
Throw New Exception("ParemeterizedSingleton has not been
properly initialized.")
End If

Return _instance
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As ParameterizedSingleton
Get

If _instance Is Nothing Then
_instance = New ParameterizedSingleton(username, password)
Else
If Not _instance.UserName = username OrElse _
Not _instance.Password = password Then

Throw New Exception("ParemeterizedSingleton has already
been initialized.")
End If
End If

Return _instance
End Get
End Property

Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class
Public NotInheritable Class Flyweight

Private _username As String
Private _password As String

Private Shared _instances As New Hashtable

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As Flyweight
Get

Dim obj As Flyweight

If _instances.Contains(username) Then
obj = DirectCast(_instances(username), Flyweight)
If obj.Password <> password Then
Throw New Exception("User '" + username + "' is already
initialized.")
End If
Else
obj = New Flyweight(username, password)
_instances(username) = obj
End If

Return obj
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String)
As Flyweight
Get
If Not _instances.Contains(username) Then
Throw New Exception("User '" + username + "' not
initialized.")
End If

Return DirectCast(_instances(username), Flyweight)
End Get
End Property
Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class

On Thu, 24 Feb 2005 23:07:35 -0000, "Paul Bromley"
<fl*******@dsl.pipex.com> wrote:
Forgive my ignorance on this one as I am trying to use a Singleton class. I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class have
a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor, but
getting an error with it. I have a feeling that I am not able to do this. Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 21 '05 #11
Thanks Herfired, excellent example of a singleton class..I've added this to
my colleciton of code snippets.

"Herfried K. Wagner [MVP]" wrote:
Errata:
Public Class Singleton


=> 'Public NotInheritable Class Singleton'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #12
Dennis,

"Dennis" <De****@discussions.microsoft.com> schrieb:
excellent example of a singleton class..I've added this to
my colleciton of code snippets.


Well, that's only the "very basic" sample. Some more information and
samples on the Singleton design pattern:

Implementing the Singleton Pattern in C#
<URL:http://www.yoda.arachsys.com/csharp/singleton.html>

Exploring the Singleton Design Pattern
<URL:http://msdn.microsoft.com/library/en-us/dnbda/html/singletondespatt.asp>

Design Pattern: Singleton in C#
<URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=486>

Design Patterns: Singleton
<URL:http://www.dofactory.com/Patterns/PatternSingleton.aspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #13
Thanks all for your help on this one, especially Sam & Herfried for the
comprehensive code samples.

Best wishes
Paul Bromley
"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:bs********************************@4ax.com...

Parameters in a Singleton depend entirely on the purpose of the
parameters. It may mean a singleton that needs initialization or you
could be talking about a different pattern--Flyweight.

If the parameters are intended to initialize the singleton and should
only be provided once, or should match if provided a second time, and
the singleton will still be a true singleton in that there will always
only be a single object whose reference won't be changed, then two
Instance properties should be implemented. One has no params and
returns the existing object only ifit has already been initialized
(throw error otherwise). The second accepts the params and if it's
the first call it initializes and returns the singleton. If it's a
subsequent call it should verify that the parameters match. See
ParameterizedSingleton below.

If the parameters are intended to represent a unique object where
there can be multiple instances of the object based on parameters but
all instances for the same parameters should be identical then the
object is not a Singleton but a Flyweight. In this case the shared
property is a collection of objects and not a single instance and is
indexed by one or both of the parameters. See Flyweight below.

HTH,

Sam
Public NotInheritable Class ParameterizedSingleton

Private _username As String
Private _password As String

Private Shared _instance As ParameterizedSingleton

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

' Singleton getters. Use Instance(username,password) first
' time to initialize the singleton and use Instance() on
' subsequent calls to use the existing singleton.

Public Shared ReadOnly Property Instance() As
ParameterizedSingleton
Get
If _instance Is Nothing Then
Throw New Exception("ParemeterizedSingleton has not been
properly initialized.")
End If

Return _instance
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As ParameterizedSingleton
Get

If _instance Is Nothing Then
_instance = New ParameterizedSingleton(username, password)
Else
If Not _instance.UserName = username OrElse _
Not _instance.Password = password Then

Throw New Exception("ParemeterizedSingleton has already
been initialized.")
End If
End If

Return _instance
End Get
End Property

Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class
Public NotInheritable Class Flyweight

Private _username As String
Private _password As String

Private Shared _instances As New Hashtable

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As Flyweight
Get

Dim obj As Flyweight

If _instances.Contains(username) Then
obj = DirectCast(_instances(username), Flyweight)
If obj.Password <> password Then
Throw New Exception("User '" + username + "' is already
initialized.")
End If
Else
obj = New Flyweight(username, password)
_instances(username) = obj
End If

Return obj
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String)
As Flyweight
Get
If Not _instances.Contains(username) Then
Throw New Exception("User '" + username + "' not
initialized.")
End If

Return DirectCast(_instances(username), Flyweight)
End Get
End Property
Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class

On Thu, 24 Feb 2005 23:07:35 -0000, "Paul Bromley"
<fl*******@dsl.pipex.com> wrote:
Forgive my ignorance on this one as I am trying to use a Singleton class. Ineed to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class havea number of paramterised constructors enabling me to pass in parameters ornot?

I am trying to use the following to send in a parmeter to a constructor, butgetting an error with it. I have a feeling that I am not able to do this. Isthere any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.

Nov 21 '05 #14
Samuel,

Many thanks for this answer. It seems that I cannot use a singleton with
parameters for what I wanted as I will not have one instance. I think my
best way around it is to access the properties using parmeters.

Best wishes

Paul Bromley

"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:bs********************************@4ax.com...

Parameters in a Singleton depend entirely on the purpose of the
parameters. It may mean a singleton that needs initialization or you
could be talking about a different pattern--Flyweight.

If the parameters are intended to initialize the singleton and should
only be provided once, or should match if provided a second time, and
the singleton will still be a true singleton in that there will always
only be a single object whose reference won't be changed, then two
Instance properties should be implemented. One has no params and
returns the existing object only ifit has already been initialized
(throw error otherwise). The second accepts the params and if it's
the first call it initializes and returns the singleton. If it's a
subsequent call it should verify that the parameters match. See
ParameterizedSingleton below.

If the parameters are intended to represent a unique object where
there can be multiple instances of the object based on parameters but
all instances for the same parameters should be identical then the
object is not a Singleton but a Flyweight. In this case the shared
property is a collection of objects and not a single instance and is
indexed by one or both of the parameters. See Flyweight below.

HTH,

Sam
Public NotInheritable Class ParameterizedSingleton

Private _username As String
Private _password As String

Private Shared _instance As ParameterizedSingleton

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

' Singleton getters. Use Instance(username,password) first
' time to initialize the singleton and use Instance() on
' subsequent calls to use the existing singleton.

Public Shared ReadOnly Property Instance() As
ParameterizedSingleton
Get
If _instance Is Nothing Then
Throw New Exception("ParemeterizedSingleton has not been
properly initialized.")
End If

Return _instance
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As ParameterizedSingleton
Get

If _instance Is Nothing Then
_instance = New ParameterizedSingleton(username, password)
Else
If Not _instance.UserName = username OrElse _
Not _instance.Password = password Then

Throw New Exception("ParemeterizedSingleton has already
been initialized.")
End If
End If

Return _instance
End Get
End Property

Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class
Public NotInheritable Class Flyweight

Private _username As String
Private _password As String

Private Shared _instances As New Hashtable

Private Sub New(ByVal username As String, ByVal password As String)
_username = username
_password = password
End Sub

Public Shared ReadOnly Property Instance(ByVal username As String,
ByVal password As String) As Flyweight
Get

Dim obj As Flyweight

If _instances.Contains(username) Then
obj = DirectCast(_instances(username), Flyweight)
If obj.Password <> password Then
Throw New Exception("User '" + username + "' is already
initialized.")
End If
Else
obj = New Flyweight(username, password)
_instances(username) = obj
End If

Return obj
End Get
End Property

Public Shared ReadOnly Property Instance(ByVal username As String)
As Flyweight
Get
If Not _instances.Contains(username) Then
Throw New Exception("User '" + username + "' not
initialized.")
End If

Return DirectCast(_instances(username), Flyweight)
End Get
End Property
Public ReadOnly Property UserName() As String
Get
Return _username
End Get
End Property

Public ReadOnly Property Password() As String
Get
Return _password
End Get
End Property

End Class

On Thu, 24 Feb 2005 23:07:35 -0000, "Paul Bromley"
<fl*******@dsl.pipex.com> wrote:
Forgive my ignorance on this one as I am trying to use a Singleton class. Ineed to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class havea number of paramterised constructors enabling me to pass in parameters ornot?

I am trying to use the following to send in a parmeter to a constructor, butgetting an error with it. I have a feeling that I am not able to do this. Isthere any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.

Nov 21 '05 #15

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

Similar topics

3
by: Rajesh Garg | last post by:
Can we have private constructors and destructors? IF yes what is the use of such constructors or destructors.....in the sense where can these be implemented in a system................. I have...
4
by: Grey Plastic | last post by:
I have several classes that all keep track of static data. However, the manner that they keep track of static data is identical, and so I'm using the template<class Child> class Parent { ... };...
2
by: John Ratliff | last post by:
What are the ramifications of creating a private copy constructor? Say I didn't want any copies to be created, say if I had a singleton for example. Should I make the copy constructor public...
7
by: Sunny | last post by:
Hi all, According C# Language Specification : 10.11 Static constructors: The static constructor for a class executes at most once in a given application domain. The execution of a static...
4
by: Sathyaish | last post by:
What is a private constructor, and why would a class have one? What are the other kinds of constructors besides: (1) public constructors; and (2) parameterized constructors And I understand...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
12
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
22
by: Peter Morris [Droopy eyes software] | last post by:
Look at these two classes public class Test { public readonly string Name; public Test(string name)
2
by: Eric Lilja | last post by:
As the topic says, I wanted to make a re-usable singleton class that could create pointers to objects with non-trivial constructors. I came up with this: #ifndef SINGLETON_HPP #define...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

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.