473,804 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Classes

I've been trying to get my head around custom classes by following the
example in the Visual Basic Language Developer's Handbook by Sybex. I think
I have a handle on what they're about, albeit a fragile one at the moment.
Having said that, I can't think of a single application for one so obviously
I need educating further. Does anyone have any practical examples of custom
classes and their application that might help me broaden my horizons?

Many thanks.

Keith.
Nov 30 '06
27 2412
>
"when I create and set the myTour = "tour id", then all of the recordsets
for bus company, hotels, rates etc gets loaded into the object."

Could you just expand a little on this please? How does the data get
loaded, do you open a recordset in a subroutine? Still missing the point
here I think!
Yes, in code I could go

dim tour1 as new clsrides
dim tour2 as new clsRides

tour1.TourID = 123 ' load tour 123
tour2.TourID = 34 'load tour 34

At this point, I have TWO tours loaded in ram, and thus go

msgbox "hotel for tour 123 is " & Tour1.HotelName

msgbox "hotel for tour 34 is" & Tour2.HotelName

So, note how the above was VERY little coding, and I can have TWO tours in
memory at the SAME time. And, even if I just need one in code...it is still
much easer then a bunch of subroutines and global variables that would trip
over them selves....

The class object is over 600 lines of code in total.....

Additional properties of the class object are outlined here:
http://www.members.shaw.ca/AlbertKal...Appendex4.html

The left side does NOT display all properties, but gives you an idea.....
the actual code in the class object for TourID is:

Public Property Let TourId(LoadID As Long)

' Loads/setsup the tour object (pricing etc..)
' DO NOT load if id is same as passed....

Dim myDB As Database
Dim qryBusList As QueryDef

Set myDB = DBEngine(0)(0)

If m_TourId <0 Then
' tour is loaded, check for same tour...
If m_TourId = LoadID Then

' tour already loaded...don't re-load
Exit Property

End If
End If

m_TourId = LoadID

' loads the load rates....

Set m_rstTour = myDB.OpenRecord set("select * from tbltours where id = " &
m_TourId)

With m_rstTour
If .RecordCount 0 Then

m_FromDate = !FromDate
m_Todate = !ToDate
m_HotelId = !Hotel
m_dtDepositDue = m_FromDate - !DaysDue

' load up hotel informaton
Set m_rstHotel = myDB.OpenRecord set("select * from tblHotels where
id = " & m_rstTour!Hotel )

' load up buses attachted to this tour
Set qryBusList = myDB.QueryDefs( "qryTourBusList B")
qryBusList.Para meters(0) = m_TourId
Set m_rstBusList = qryBusList.Open Recordset

' load up seasonal pricing talbes
Call TLoadRates

' set tax tax.
If m_rstTour!NoGst = True Then
m_GstRate = 0
Else
m_GstRate = gblGst(m_FromDa te)
m_PstRate = gblPst(m_FromDa te)
End If

Else
m_TourId = 0
End If
End With

End Property

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
Dec 2 '06 #21
By the way, that appendix link where I outline that access class object is

is part of larger article here:

http://www.members.shaw.ca/AlbertKal...000000003.html

In that article, I explain why I used class objects in ms-access....

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com

Dec 3 '06 #22
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:%Ooch.4118 71$R63.320926@p d7urf1no...
By the way, that appendix link where I outline that access class object is

is part of larger article here:

http://www.members.shaw.ca/AlbertKal...000000003.html

In that article, I explain why I used class objects in ms-access....

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
Many thanks Albert (and Gord), I shall read though all of this today.

Regards,
Keith.
Dec 4 '06 #23
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:GGoch.4118 63$R63.146206@p d7urf1no...

tour1.TourID = 123 ' load tour 123
tour2.TourID = 34 'load tour 34

At this point, I have TWO tours loaded in ram, and thus go

msgbox "hotel for tour 123 is " & Tour1.HotelName

msgbox "hotel for tour 34 is" & Tour2.HotelName
<snip>
>
the actual code in the class object for TourID is:

Public Property Let TourId(LoadID As Long)
Albert,

Dumb question: how do you supply the argument to the property? You have
"tour1.Tour ID = 123" but wouldn't you get an "argument not optional" error
there?

Thanks for your patience, I'll get the hang of this yet!

Keith.
Dec 4 '06 #24

Keith Wilby wrote:
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:GGoch.4118 63$R63.146206@p d7urf1no...
>
tour1.TourID = 123 ' load tour 123
tour2.TourID = 34 'load tour 34

At this point, I have TWO tours loaded in ram, and thus go

msgbox "hotel for tour 123 is " & Tour1.HotelName

msgbox "hotel for tour 34 is" & Tour2.HotelName
<snip>

the actual code in the class object for TourID is:

Public Property Let TourId(LoadID As Long)

Albert,

Dumb question: how do you supply the argument to the property? You have
"tour1.Tour ID = 123" but wouldn't you get an "argument not optional" error
there?
Property Let statements behave differently than Function and Sub
statements do. 123 *is* the argument.

Dec 4 '06 #25
"Gord" <gd*@kingston.n etwrote in message
news:11******** **************@ l12g2000cwl.goo glegroups.com.. .
>
>>
Dumb question: how do you supply the argument to the property? You have
"tour1.TourI D = 123" but wouldn't you get an "argument not optional"
error
there?

Property Let statements behave differently than Function and Sub
statements do. 123 *is* the argument.
Thanks for your patience Gord. Another dumb question but hopefully the
answer will make the penny drop. In a simple example, if I have a table
"tblHoliday s" with fields "ID" and "Country" and I have a class
"clsHoliday ", how do I set and retrieve a "Country" property? I'm calling
the class using:

Dim hlHoliday As clsHoliday
Set hlHoliday = New clsHoliday
hlHoliday.HolID = "ABC123"

Here's the class code:

Property Let HolID(strID As String)

Dim db As DAO.Database, rs As DAO.Recordset
Dim strCountry As String
Set db = CurrentDb
Set rs = db.OpenRecordse t("Select * from tblHolidays Where ID = '" & strID &
"'")
With rs
If .RecordCount 0 Then
'*** What goes here to get the other properties? ***
End If
End With

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Property
Dec 5 '06 #26
Keith Wilby wrote:
"Gord" <gd*@kingston.n etwrote in message
news:11******** **************@ l12g2000cwl.goo glegroups.com.. .
>
Dumb question: how do you supply the argument to the property? You have
"tour1.Tour ID = 123" but wouldn't you get an "argument not optional"
error
there?
Property Let statements behave differently than Function and Sub
statements do. 123 *is* the argument.

Thanks for your patience Gord. Another dumb question but hopefully the
answer will make the penny drop. In a simple example, if I have a table
"tblHoliday s" with fields "ID" and "Country" and I have a class
"clsHoliday ", how do I set and retrieve a "Country" property? I'm calling
the class using:

Dim hlHoliday As clsHoliday
Set hlHoliday = New clsHoliday
hlHoliday.HolID = "ABC123"

Here's the class code:

Property Let HolID(strID As String)

Dim db As DAO.Database, rs As DAO.Recordset
Dim strCountry As String
Set db = CurrentDb
Set rs = db.OpenRecordse t("Select * from tblHolidays Where ID = '" & strID &
"'")
With rs
If .RecordCount 0 Then
'*** What goes here to get the other properties? ***
End If
End With

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Property
Hi, Keith. Try this:

'-----start of class module----
Option Compare Database
Option Explicit

Private mstrHolID As String
Private mstrCountry As String

Public Property Get HolID() As String
' return the property value
HolID = mstrHolID
End Property

Public Property Let HolID(ByVal strID As String)
Dim db As DAO.Database, rs As DAO.Recordset

' save the ID property value
mstrHolID = strID

' retrieve other attributes
Set db = CurrentDb
Set rs = db.OpenRecordse t( _
"Select * from tblHolidays Where ID = '" & strID & "'")
With rs
If .RecordCount 0 Then
'*** What goes here to get the other properties? ***
mstrCountry = rs!Country
End If
End With

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Property

Public Property Get Country() As String
' return the property value
Country = mstrCountry
End Property
'-----end of class module----
'-----start of usage example----
Sub HolidayTest()
Dim hlHoliday As clsHoliday

Set hlHoliday = New clsHoliday
hlHoliday.HolID = "ABC123"
Debug.Print hlHoliday.Count ry

Set hlHoliday = Nothing
End Sub
'-----end of usage example----

Dec 5 '06 #27
"Gord" <gd*@kingston.n etwrote in message
news:11******** **************@ n67g2000cwd.goo glegroups.com.. .
>
Hi, Keith. Try this:
<snip>

Duh, I feel so stupid now ;-) The penny has finally dropped, for this
example at least. Many thanks again Gord.

Keith.
Dec 5 '06 #28

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

Similar topics

3
1976
by: Neil Zanella | last post by:
Hello, In Python, classes are objects. But there is no way to custom print a class object. This would require some syntax such as the one commented out below: With the current "foo = classmethod(foo)" mechanism custom printing for class objects is not possible. #!/usr/bin/python class Foo:
7
2924
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031" validate="True"/> </httpHandlers>
5
6916
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
12
5343
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
8
2024
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object like so: <Teachers> <Teacher> <Classes> <Class>
0
1839
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object 'School.Teacher' as an ArrayList creates the proper information (see aspx code below), but I'm unable to use this ArrayList in the Profile object. The aspx code below shows the attempt and error message.
19
4922
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
2
2533
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in Development Environment; may be a few example(s) will help me understand.
2
5116
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
0
10558
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
10318
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...
0
10069
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
9130
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...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.