Question : VBA classes

I have a number of functions now with the help of the experts. These may be used across multiple databases. is it better to add these functions in a class module with methods to get and return the values or just keep copying and pasting the functions in a normal module?

Answer : VBA classes

I work with a LOT of classes and find then very useful, but I agree with Jim on this one - there's little reason to create classes for utility functions. Classes are very useful IF you need to create more than one of the same item - for exmaple, if you need to create classes to hold the properties of a dozen Vehicles - but for utility functions you'll only be using one of those at a time.

In specific regard to your isse:

Sub vehicles()
Dim Car As Vehicle ' THIS IS FINE VEHICLE FOUND
Set Car = New Vehicle ' AFTER NEW VEHICLE DOES NOT APPEAR
End Sub

You indicate that the name of your CLASS is "DataTests", not "Vehicle". Vehicle is a User-Defined Type declared in the Class Module named DataTests, and as such you won't be able to get to it (matter of fact, you'll find it imposisble to work with a UDT define in a Class Module from outside that class module). UDTs are generally used as internal data structures within the class, and the Properties of the class are used to handle the input/output to/from the class. The UDT is simply used to store the data inside that instance of the calss.

The correct way to do that is:

Dim Car As DataTests
Set Car = New DataTests

Msgbox Car.bHP

Also, there is little reason to use both (a) a UDT and (b) individual variables to store internal class data. Use one or the other, not both.




Random Solutions  
 
programming4us programming4us