Can't use New?

  • Thread starter Thread starter Joel Whitehouse
  • Start date Start date
J

Joel Whitehouse

Hello all,

I added an ocx file (a VB6 usercontrol that I made) as a reference in my
vb.net project. However, when I try to instantiate a new copy of the
control class with the following line:

Private m_hpib As New HPIB

I get this error:

'C:\MyProjects\Antenna Test Range Control\Antenna Test Range
Control\modHPIB.vb(5): 'IoTechHPIBControl.HPIBClass.Private Sub New()'
is not accessible in this context because it is 'Private'.

How can I create an instance of th class if I can't use the "New" keyword??

-Joel
 
since the ctor is marked private, you really have no options -- are
there any public constructors? also, is there another object that
returns this type of object?
 
stand__sure said:
since the ctor is marked private, you really have no options -- are
there any public constructors? also, is there another object that
returns this type of object?

No other objects return this kind of object. I'm not sure if there are
any public constructors, but if there were, wouldn't the New keyword
specify them by default?

-Joel
 
Joel said:
No other objects return this kind of object. I'm not sure if there are
any public constructors, but if there were, wouldn't the New keyword
specify them by default?

When you say eg

Dim myX As New X

, you are saying you want to use that constructor of X that takes no
parameters. For this particular class, that constructor is marked
Private, so you can't use it. It may happen that the class has other
constructors - for example, it might have a

Public Sub New(s As String)

in which case you would be allowed to create one with

Dim myX As New X("some string")

The compiles works out which constructor to use by looking at the
arguments you supply, just as with any over overloaded procedure.

In this case since you say it is authored by you, you just need to
check you have set the accessors on your constructors correctly.
 
Larry said:
in which case you would be allowed to create one with

Dim myX As New X("some string")

Thanks - I'll look into this. That's a handy thing to know!

-Joel
 
Larry said:
In this case since you say it is authored by you, you just need to
check you have set the accessors on your constructors correctly.

Well see, it's authored by me, but since I wrote it in VB6, I can't use
the New keyword as the name for a sub routine. Is there any other way
that I can make a public constructor through VB?

-Joel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top