473,804 Members | 3,375 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

Keith Wilby wrote:
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:JS******** ********@newssv r27.news.prodig y.net...

An easy example where *using* a class can be easier. Take my Email class.
As a class it works something like this.

Dim msg as New CDOMsg

With msg
.AddRecipient(" SomeAddress")
.Subject = "foo"
.TextBody = "bar"
.Send
End With
<snip>

Many thanks Rick. I think I'm OK using the class, it's what's in the class
itself that my small brain is struggling with. Here's what I have in my
Employee class so far:

Private mstrLastName As String
Private mstrFirstName As String
Private mdteDOB As Date
Private mintEmployeeNo As Integer

Property Get LastName()
LastName = mstrLastName
End Property

Property Get FirstName()
FirstName = mstrFirstName
End Property

Now it's the properties that are stumping me here because when I create a
new instance of Employee I want to assign values:

Dim objEmployee As clsEmployee
Set objEmployee = New clsEmployee
objEmployee.Las tName = "Wilby"
objEmployee.Fir stName = "Keith"

but of course this doesn't work. I'm not sure what's happening in those
property declarations.
The Property Get statements allow you to retrieve the value of the
named property. A Property Let statement will enable you to give the
property a value. I have never been a "classy" programmer , but I
believe the magic you seek is

Property Let LastName(ByVal vNewValue As Variant)
mstrLastName = vNewValue
End Property

(I'm sure that someone will correct me if I am wrong.)

Nov 30 '06 #11
"Gord" <gd*@kingston.n etwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
>

The Property Get statements allow you to retrieve the value of the
named property. A Property Let statement will enable you to give the
property a value. I have never been a "classy" programmer , but I
believe the magic you seek is

Property Let LastName(ByVal vNewValue As Variant)
mstrLastName = vNewValue
End Property

(I'm sure that someone will correct me if I am wrong.)
Clearly I have much to learn still. Many thanks for that pointer Gord, I
will now go back to my book!

Regards,
Keith.
Nov 30 '06 #12
Keith,

Your problem here is that oyu have followed sound programming
principles. You have created your variables within your class as
Private. Therefore, only methods and functions within your class can
access them, same as a private variable anywhere else for that matter.
As Gord correctly noted, these Get and Let methods can be accessed
publicly and therefore will allow non-local functions and procedures
that have an instance of your class to modify/view those values.

PS. You took the "unintersti ng path" and chose the employee and not
the slot machine ;)

Cheers,
Jason Lepack

Keith Wilby wrote:
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:JS******** ********@newssv r27.news.prodig y.net...

An easy example where *using* a class can be easier. Take my Email class.
As a class it works something like this.

Dim msg as New CDOMsg

With msg
.AddRecipient(" SomeAddress")
.Subject = "foo"
.TextBody = "bar"
.Send
End With
<snip>

Many thanks Rick. I think I'm OK using the class, it's what's in the class
itself that my small brain is struggling with. Here's what I have in my
Employee class so far:

Private mstrLastName As String
Private mstrFirstName As String
Private mdteDOB As Date
Private mintEmployeeNo As Integer

Property Get LastName()
LastName = mstrLastName
End Property

Property Get FirstName()
FirstName = mstrFirstName
End Property

Now it's the properties that are stumping me here because when I create a
new instance of Employee I want to assign values:

Dim objEmployee As clsEmployee
Set objEmployee = New clsEmployee
objEmployee.Las tName = "Wilby"
objEmployee.Fir stName = "Keith"

but of course this doesn't work. I'm not sure what's happening in those
property declarations. The logical part of my brain has quit for Christmas
already I think.

Keith.
Nov 30 '06 #13
Keith Wilby wrote:
"Gord" <gd*@kingston.n etwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
>>

The Property Get statements allow you to retrieve the value of the
named property. A Property Let statement will enable you to give the
property a value. I have never been a "classy" programmer , but I
believe the magic you seek is

Property Let LastName(ByVal vNewValue As Variant)
mstrLastName = vNewValue
End Property

(I'm sure that someone will correct me if I am wrong.)

Clearly I have much to learn still. Many thanks for that pointer
Gord, I will now go back to my book!

Regards,
Keith.
The problem is you made those properties Private. Private properties are
either intended to be used strictly within the class or must have a Let (or
Set) function that can be used by code outside the class.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Nov 30 '06 #14
Lyle Fairfield wrote:
Keith Wilby wrote:
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?

There aren't a lot of uses for classes. The major one is to make
programers/developers feel that they have arrived.
I use my own classes almost never but over the years I have defended
them as useful for:
1. standardizing procedures in an application developed by many
persons; for example an append class;
2. allowing for multiple instances of code to exist concurrently; for
example code that persisted values while forms were closed and opened;
3. code which used objects or properties whose creation and or
initialization were time consuming; for example a numerals to words
procedure where arrays and strings were used.

You have used classes extensively if you have used forms that have
modules, and I expect that you have. The form module is, for all
extents [:-)] and purposes, a class module. It has initalization and
termination procedures (form_open and form_close), properties in the
form of controls or property definitions, and can have multiple
instances. IMO the form is a very superior Class. When invisible it
acts just like a class. It can be made visible on demand (and invisible
again on demand) to get input from the user, to show as progress bar,
to show a message, etc and as a single default entity it does not have
to be initialized; we can jst call Form_MYClass.Do Something()
[DoSomething is a Public Procedure] and slam, bam it's done.
Slam, bam, thank-you RAM? Is that from a call to
Form_ClassicRoc k.GetAlteredLyr icSnippet()?

James A. Fortune
CD********@Fort uneJames.com

Nov 30 '06 #15
I give some thoughts and helpfull advice here:
Using Class objects with ms-access.
By Albert D. Kallal
Tuesday, September 16, 2003

Why would I want to use a class object in ms-access?

http://www.members.shaw.ca/AlbertKal.../WhyClass.html
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com

Nov 30 '06 #16
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:GkHbh.3984 09$5R2.297739@p d7urf3no...
>I give some thoughts and helpfull advice here:
Using Class objects with ms-access.
By Albert D. Kallal
Tuesday, September 16, 2003

Why would I want to use a class object in ms-access?

http://www.members.shaw.ca/AlbertKal.../WhyClass.html
Thank you Albert, I will read that now.
Dec 1 '06 #17
"jlepack" <jl*****@gmail. comwrote in message
news:11******** **************@ l39g2000cwd.goo glegroups.com.. .
Keith,

Your problem here is that oyu have followed sound programming
principles. You have created your variables within your class as
Private. Therefore, only methods and functions within your class can
access them, same as a private variable anywhere else for that matter.
As Gord correctly noted, these Get and Let methods can be accessed
publicly and therefore will allow non-local functions and procedures
that have an instance of your class to modify/view those values.
Duly noted, thanks.
>
PS. You took the "unintersti ng path" and chose the employee and not
the slot machine ;)
That's the kinda guy I am ;)
>
Cheers,
Jason Lepack

Dec 1 '06 #18
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:GkHbh.3984 09$5R2.297739@p d7urf3no...
>I give some thoughts and helpfull advice here:
Using Class objects with ms-access.
By Albert D. Kallal
Tuesday, September 16, 2003

Why would I want to use a class object in ms-access?

http://www.members.shaw.ca/AlbertKal.../WhyClass.html
Just a quick question Albert.

"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!

Thanks.

Keith.
Dec 1 '06 #19

Keith Wilby wrote:
"Albert D. Kallal" <Pl************ *******@msn.com wrote in message
news:GkHbh.3984 09$5R2.297739@p d7urf3no...
I give some thoughts and helpfull advice here:
Using Class objects with ms-access.
By Albert D. Kallal
Tuesday, September 16, 2003

Why would I want to use a class object in ms-access?

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

Just a quick question Albert.

"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!

Thanks.

Keith.
Hi, Keith.

Here is a simple example of what I *think* Albert is driving at. Notice
that the "Property Let "Salary_Gra de" not only saves the Salary_Grade
you pass it, as in...

objEmployee.Sal ary_Grade = 3

....but it also looks up the corresponding Annual_Salary and saves that
as well, so you can retrieve it via...

objEmployee.Ann ual_Salary

....without doing the lookup yourself.
'-----class module code follows-----

Option Compare Database
Option Explicit

Private mstrLastName As String
Private mintSalary_Grad e As Integer
Private mcurAnnual_Sala ry As Currency

Public Property Get LastName()
' return property value
LastName = mstrLastName
End Property

Public Property Let LastName(ByVal vNewValue As Variant)
' store property value
mstrLastName = vNewValue
End Property

Public Property Get Salary_Grade() As Variant
' return property value
Salary_Grade = mintSalary_Grad e
End Property

Public Property Let Salary_Grade(By Val vNewValue As Variant)
' store property value...
mintSalary_Grad e = vNewValue
' ... and look up annual salary from reference table
mcurAnnual_Sala ry = _
DLookup("Annual _Salary", "Salaries", "Salary_Gra de=" &
mintSalary_Grad e)
End Property

Public Property Get Annual_Salary() As Variant
' return property value
Annual_Salary = mcurAnnual_Sala ry
End Property

Dec 1 '06 #20

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
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
1
10302
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
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...
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.