473,395 Members | 1,341 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,395 software developers and data experts.

Hiding Default Constructor in VB Express 2005 (Public Not Creatable in VB6)

Hello,

I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.
Regards

Holger
Nov 14 '06 #1
7 2547
Can't you just mark the class as mustinherit?

i.e.

Public MustInherit MyClass()
....
End Class

Thanks,

Seth Rowe
Holger Boskugel wrote:
Hello,

I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.
Regards

Holger
Nov 14 '06 #2
On Nov 14, 6:17 am, "Holger Boskugel" <news.p...@vbwebprofi.dewrote:
I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.


Private Sub New()
End Sub

Nov 14 '06 #3
Hello Seth,
I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.
Can't you just mark the class as mustinherit?

i.e.

Public MustInherit MyClass()
...
End Class
no, I can't in case that I need the class as a Public and will be instanced
through functions in my class library
Regards

Holger
Nov 14 '06 #4
Hello Chris,
I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.
Private Sub New()
End Sub
This was what I checked out, but if I reference the library in an
other project, class becomes a default public ctor, that is what
I don't want.
Regards

Holger
Nov 14 '06 #5
Holger Boskugel wrote:
Private Sub New()
End Sub

This was what I checked out, but if I reference the library in an
other project, class becomes a default public ctor, that is what
I don't want.
I'm not sure what you mean here. If you provide a Private Sub New,
then the class cannot be instantiated directly from another class. The
compiler only supplies a default constructor if you don't explicitly
declare one. As for inheritance, constructors are not inherited so any
derived classes will have to have a private constructor as well if you
want to prevent them from being instantiated directly.

Nov 15 '06 #6
Hello Chris,
Private Sub New()
End Sub
This was what I checked out, but if I reference the library in an
other project, class becomes a default public ctor, that is what
I don't want.
I'm not sure what you mean here. If you provide a Private Sub New,
then the class cannot be instantiated directly from another class. The
compiler only supplies a default constructor if you don't explicitly
declare one. As for inheritance, constructors are not inherited so any
derived classes will have to have a private constructor as well if you
want to prevent them from being instantiated directly.
It's problem of missviewing in the VB.NET Express 2005 IDE. The IDE
adds allways a Public Default Constructor to my classes in class view,
which not exists. I have now tried all kinds of Construtors, the test can
be download from this URL :

http://www.vbwebprofi.de/public/_new...nstructors.zip

The result of my test is that

Protected Friend Sub New()

or

Protected Friend Sub New(ByVal in_Parameter As Object)

and

Friend Sub New()

or

Friend Sub New(ByVal in_Parameter As Object)

fit the former Public Not Creatable in VB6. The both first implementations
give programmers the option to inherit my class and call my own constructor
with MyBase.New() or MyBase.New(MyParameter).
Regards

Holger
Nov 15 '06 #7
If you add a constructor to your class that has arguments, but don't add
a default (argument-less) constructor, that should hide the default constructor.

Public Class SomeClass
Public Sub New(ByVal startupInfo As Object)
' ----- Add relevant code here.
End Sub
End Class

Users of SomeClass will now be required to pass an argument to the constructor;
just calling "New SomeClass" will not work.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Hello,

I'm looking for a solution to hide the default constructor of a class.
In VB6 there was a class type of "Public Not Creatable". I have
tried to write the default ctor as friend or private but the compiler
adds a default ctor. Actual I use the way to set the default ctor
as protected and inside I raise an error if this ctor will be called
from an inheriting class.
Regards

Holger

Nov 15 '06 #8

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

Similar topics

19
by: Andrew J. Marshall | last post by:
I want to create a class that must receive a parameter when instantiated. In other words, I do not want it to have a "Public Sub New()". 1) Does VB.NET create a default public constructor if I do...
12
by: Wes Spikes | last post by:
Ok, first things first: I'm a VB classic programmer and am considering upgrading now that I've seen VB2005. .NET1 & 1.5 never seemed to appeal to me, but now I'm considering the 2005. Does anyone...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
9
by: Al_C | last post by:
What is the future of VB express? We're doing an app in VB2003 and like some of the VB controls in VS2005. Is VB Express a serious product? Let's face it, the price makes me wonder? Free is never...
6
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
8
by: Zardax | last post by:
Hi !!! I need to know if there is compatibility between VB 6.0 and Visual Basic 2005 Express Everything I need is to compile the VB 6.0 code in Visual Basic 2005 Express without re-write the...
2
by: W C Hull | last post by:
I know that I can download a copy of Visual Basic 2005 Express for free. My question is this..... I have Visual Basic 6.0 Professional and was wondering if anyone that has used the packages can...
25
by: Marco | last post by:
Hi everyone. I've been trying to move some small applications written in vb.net 2003 to vb.net 2005 express just for testing purposes. I have noticed so far that the applications seem to run ...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
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...

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.