Class or Module

Guus2005

AWF VIP
Local time
Today, 03:38
Joined
Jun 26, 2007
Messages
2,631
What's the criterium for creating a class when i also could create a set of functions?

Code:
'My clsHourglass class
Option Compare Database
Option Explicit
'This class sets the hourglass on and off, even when forgotten.

Private Sub Class_Terminate()

    HourGlassOff

End Sub

Public Sub HourGlassOn()

    DoCmd.Hourglass True

End Sub

Public Sub HourGlassOff()

    DoCmd.Hourglass False

End Sub
The use for the above code is clear. It turns off the hourglass even when you have forgotten to do it. When exiting the function in which it was created the class terminated automatically.

I have an applicants application where resume's, photo's and minutes are stored.

I want to create a directory structure for my program in which it can store export and saved files. It is a set of 7 subdirectories which reside on the applicants directory which must be created automatically.

I can create a Class or set of functions to create the directory tree, copy, delete and open files to/from the applicants subdirectory.

Is there a rule which states that when done/wanted that, do this?

Thx 4 your time.
 
there is no rule.

if you are comfortable creating a class, or want to give it a try, do it. as they say, it might take some time to set up, but it will pay off later.

i created one recently to calculate the sum (price) of rows in a subform. i originally did the calculation in code behind. with every record i moved to on the main form, the calculation took about a second to show up. i added another textbox to show the results that came from the class and the results showed up instantly. classes good.

a one-line snippet of code like the hourglass might not be worth it, but there's no real reason not to either, especially if you'll use it a lot. in a case like that you'll want to keep all the property/method names short or (perhaps) it won't be worth it. still a good exercise though, and why not.
 
I'm with Wazz on this. Classes are good, fast, and robust and definitely worth exploring. You have to shift your coding paradigm a bit, like you'll start to feel like you're solving problems from the inside out, rather than from the outside in.
But it's so worth it.
 
I don’t think the code supplied requires a class nor is it well written.

Why would the Terminate Sub require two Subs when a common Sub could be passed an argument True/False?
What would happen if the Class caused an error; does it terminate the Class and if not how would it turn off the Hourglass?
You don’t have error handling in any of the code so far posted, and there’s a lot of that sort of thing posted on the WWW.
There is no guarantee it would be faster.

The above code has nothing to do with a directory/file class.

There is no silver bullet because it depends on what you are trying to do in Access.
When the numbers of controls on a Form grow, or a control type needs altering to do something it can’t do natively, it can be useful but it then depends on WithEvents to extract the real worth.

The WithEvents were not mentioned as in: -

Private WithEvents lblThisLabel As Label

Without WithEvents you might as well write a Public procedure.
 

Users who are viewing this thread

Back
Top Bottom