473,807 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instantiate class within a class

Hi all,

I currently use a class to interface with my databases, allowing me to
insert, update, delete and retrieve records from the database as methods of
the class.

I have now created a recordset class and want to in some way instantiate
this class via the database class i.e.

Set objDbase = New cDatabase
With objDbase
.Database = "/db/db.mdb"
.Connect
End With

........ other code ........

Set rsObj = New objDbase.Record set
......... RS Manipulation methods in the cRecordset class

Set objDbase = Nothing
I have experimented with 'Property Set' Within the cDatabase class but to no
avail, as follows

Public Property Set Recordset (cRecordset)
Set i_rs = New cRecordset
End Property
Public Property Get Recordset ()
Set Recordset = i_rs
End Property

I confess to being a novice with 'Property Set' having never used it before,
and I can't seem to find any practical examples of it online. I know JScript
supports inheritance to a degree, but need to work with vbscript at the
moment.

BTW the idea behind all this is to be able to instantiate independant
pseudo-recordsets so they can be paginated/manipulated independantly. This
could not be done efficiently using the dbase class alone when it's instance
existed from beginning to end of a page, or another class. The reason I want
to do it as a property is so that each one can be individually referenced
instead of using a fixed internal variable in the dbase class for each rs
class, which would defeat the purpose of the rs class.

Hopefully that makes sense to someone out there! Any insight, information,
drection or advice on instantiating classes like this within a class in
classic asp/vbscript would be gratefully appreciated, even if it's to say
'that's not the way to go about it'!

Thanks in advance,
Colin
Jul 19 '05 #1
2 4718
> Public Property Set Recordset (cRecordset)
Set i_rs = New cRecordset
End Property


You maybe confusing things here. You have declared that the property expects
you to assign it an object that you will call cRecordset, but then inside the
property you try to instantiate a cRecordset object. I'm not entirely sure
what is going to happen, but I can tell this isn't what you were trying to
achieve.

If you are trying to pass an existing recordset to the object you might ant
to go with something like:

Public Property Set Recordset(aRecS et)
Set i_rs = aRecSet
End Property

this will assign the incoming assigned recordset to your internal recordset
variable.

If your trying to have the objDbase object instantiate and return a new
Recordset object you may want to createa seperate function or property to do
so. Something like:
Function GetNewRecordset ()
Set GetNewRecordset = New cRecordset
End Function
You would not needto use the new keyword in your calling code, that is
handled here internally, so basically your code would look like:

Set rsObj = objDBase.GetNew Recordset()

Hope this was what you were looking for,

-T
Jul 19 '05 #2
Thanks Tarwin,

Your exactly right of course, did that and it worked a treat. Now all I have
to do is to figure out how to paginate a 2 dimensional array :)

Each solution creates a new set of problems :)

Thanks for your reply
Colin
"Tarwn" <Ta***@discussi ons.microsoft.c om> wrote in message
news:15******** *************** ***********@mic rosoft.com...
Public Property Set Recordset (cRecordset)
Set i_rs = New cRecordset
End Property
You maybe confusing things here. You have declared that the property

expects you to assign it an object that you will call cRecordset, but then inside the property you try to instantiate a cRecordset object. I'm not entirely sure
what is going to happen, but I can tell this isn't what you were trying to
achieve.

If you are trying to pass an existing recordset to the object you might ant to go with something like:

Public Property Set Recordset(aRecS et)
Set i_rs = aRecSet
End Property

this will assign the incoming assigned recordset to your internal recordset variable.

If your trying to have the objDbase object instantiate and return a new
Recordset object you may want to createa seperate function or property to do so. Something like:
Function GetNewRecordset ()
Set GetNewRecordset = New cRecordset
End Function
You would not needto use the new keyword in your calling code, that is
handled here internally, so basically your code would look like:

Set rsObj = objDBase.GetNew Recordset()

Hope this was what you were looking for,

-T

Jul 19 '05 #3

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

Similar topics

2
2482
by: jerrygarciuh | last post by:
Hello, Is it possible to instantiate a child class within the constructor of its parent? eg Class DBI extends DB { function DBI() { // explicit parent constructor call
5
2378
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
4
1085
by: Didier Willame | last post by:
Hello, I would like to use the 'foo' class stored in http://www.argonauts-it.be/foo.php . This the code ( http://www.argonauts-it.be/test.php ) : <?php ignore_user_abort( true );
1
1799
by: John | last post by:
Another Best Performances Practice Question: Here's the scenario, as some of you who viewed and responded to my earlier question already know: I have a public class (csValidation) which contains different validation functions. These functions will be called from within many different forms when a textbox is filled in by the user. I have an event in the form that checks the textbox and opens up the validation function in the csValidation...
14
1483
by: Ray5531 | last post by:
I have a console application in my local computer which I like to use remoting in it,to instanciate an object (MyClass.dll) in a web application(its bin folder) in a completely seperated box(in the same domain thought) .I have two questions: 1)Is my case covered in "Remoting objects hosted in IIS" topic?Are they same? 2) How should I authenticate to IIS from my console application? Do I really need to authenticate to IIS before...
6
1236
by: Chris Kennedy | last post by:
I have a dataset, datatable and data row which I have declared public in my class. I instantiate them in one sub routine and go to use them again and I get an 'Cannot find table 0' wrror Public objds as new dataset() Public objDataTable As new DataTable() Public objRow As DataRow Sub 1 Create dataset and use sucessfully
3
1604
by: Nuno | last post by:
How can I instantiate a webform2 object from webfrom1 codebehind? The class does not popup in intellisense and gives me and error if i try to create it. Nuno
2
1343
by: Pyenos | last post by:
class model:pass class view: model() class controller: model() I can instantiate clsss model from inside class view but I can't instantiate class model from inside controller, due to the nature of python interpreter.
4
2444
by: Phil Latio | last post by:
Here is some basic example code: $newUser = new User(); if ($newUser->SaveNewUser()) { echo "success"; } else { echo "failure";
0
9720
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10626
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10112
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.