473,790 Members | 2,734 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 #1
27 2411
Anything can be a custom class. Think of anything that has multiple
variables and you can make it into a custom class.

Take an Employee for example. I am an employee, you presumably are an
employee.

At the root, all employees have a first name, last name, birthdate,
SSN, etc. You could store each of those variables and have a
JasonLepack as Employee, or a KeithWilby as Employee.

Another example is a slot machine. Each slot machine has a few
variables.
It has a cost structure, payout structure, amount of money in it, data
on the reels, current position of reels.

On top of that a slot machine has actions (functions) that can be
performed. You could depositMoney, pullArm, fullPlay (the button on
the front), payOut.

Hope that makes a little more sense.

Cheers,
Jason Lepack

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?

Many thanks.

Keith.
Nov 30 '06 #2
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?
Many thanks.

Keith.
I have classes that ...

Provides the Windows File Browser dialog
Creates and sends an Email using Outlook
Creates and send an Email using CDO
Displays a custom Message Dialog Form
(others that are to esoteric to bother describing)

There are times when having a bunch of related code in a class is better
than just having functions and sub-routines in a module. Classes can expose
certain things while not exposing others. You can instantiate multiple
objects of a Class at the same time. Since they are instantiated as objects
you can pass them around between other functions and sub-routines.

I'm not an expert at using them in Access and Classes in VBA have some
limitations, but they definitely have their place. Some developers uses
classes more than others especially if they came from a programming
background where object-oriented was stressed.

It is good to learn about Classes and be able to dig into those you
encounter and see what's going on, but don't feel guilty if you can't think
of hundreds of ways to use them. In most cases plain old functions and
sub-routines solve the problem in the best fashion.

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

Nov 30 '06 #3

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.

Nov 30 '06 #4
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:sw******** ********@newssv r27.news.prodig y.net...
>
It is good to learn about Classes and be able to dig into those you
encounter and see what's going on, but don't feel guilty if you can't
think of hundreds of ways to use them. In most cases plain old functions
and sub-routines solve the problem in the best fashion.
You've hit the nail right on the head there Rick because I do extensively
use subs/functions to return values and perform various tasks, I suppose I'm
going to have to keep reading up until the penny fully drops to see if any
would be more efficient as a class. Thanks for your response.

Keith.
Nov 30 '06 #5
"jlepack" <jl*****@gmail. comwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Anything can be a custom class. Think of anything that has multiple
variables and you can make it into a custom class.

Take an Employee for example. I am an employee, you presumably are an
employee.

At the root, all employees have a first name, last name, birthdate,
SSN, etc. You could store each of those variables and have a
JasonLepack as Employee, or a KeithWilby as Employee.
<snip>

Thanks Jason, I'll have a go at creating one of those, should help that
penny drop.

Regards,
Keith.
Nov 30 '06 #6
"Lyle Fairfield" <ly***********@ aim.comwrote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
<snip>

Thanks Lyle.
Nov 30 '06 #7
Keith Wilby wrote:
"jlepack" <jl*****@gmail. comwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
>Anything can be a custom class. Think of anything that has multiple
variables and you can make it into a custom class.

Take an Employee for example. I am an employee, you presumably are
an employee.

At the root, all employees have a first name, last name, birthdate,
SSN, etc. You could store each of those variables and have a
JasonLepack as Employee, or a KeithWilby as Employee.
<snip>

Thanks Jason, I'll have a go at creating one of those, should help
that penny drop.

Regards,
Keith.
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

Now, that class has lots of other properties and methods that I might use
from time to time, but most often I only use the ones you see above. If I
wrote that as a standard function I would have to write it out with a bunch
of comma separated arguments and include all the commas for the arguments I
don't use and all optional arguments would have to be specified at the end
of the function signature. I could use the named argument syntax with a
standard function and "almost" do it the same as with the class, but its
just nicer to be able to use the class syntax.

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

Nov 30 '06 #8
"jlepack" <jl*****@gmail. comwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
>
Take an Employee for example. I am an employee, you presumably are an
employee.

At the root, all employees have a first name, last name, birthdate,
SSN, etc. You could store each of those variables and have a
JasonLepack as Employee, or a KeithWilby as Employee.
Any chance of posting an example Jason?

Keith.
Nov 30 '06 #9
"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 #10

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

Similar topics

3
1975
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
2923
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
6914
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
12
5342
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
2023
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
1837
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
4921
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
2530
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
9666
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
10413
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...
1
10145
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
9021
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
7530
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
6769
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
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
3
2909
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.