class module assigment

  • Thread starter Thread starter asc4john
  • Start date Start date
A

asc4john

I am building a class module in VBA and would like to know if it
possible to have assigment automactically call a function to calulate a
value. Like so: myClass.variable = 47 would do this myClass.variable
= (someFunction(47))
 
asc4john said:
I am building a class module in VBA and would like to know if it
possible to have assigment automactically call a function to calulate a
value. Like so: myClass.variable = 47 would do this myClass.variable
= (someFunction(47))

Maybe I am missing something here, but what is point of declaring it a
variable, if what you want is a function call? Why not call
myClass.someFunction(47) directly?
 
I am building a class module in VBA and would like to know if it
possible to have assigment automactically call a function to calulate a
value. Like so: myClass.variable = 47 would do this myClass.variable
= (someFunction(47))

You're probably a C++ programmer ... ?? Unfortunately, VBA is not C++
(not even an OOP language), and there is no such thing as polymorphism
nor overloading of built-in operators in VBA.

However, you might be able to implement what you want using Properties
(Property Get / Property Let). Define a Property for your object;
assigning a value to it will call the "Property Let" function which
you can write yourself.

As in C++, the actual variables contained in an object should usually
be declared Private ... access to the variables is done mostly through
Properties.
 
asc4john said:
I am building a class module in VBA and would like to know if it
possible to have assigment automactically call a function to calulate a
value. Like so: myClass.variable = 47 would do this myClass.variable
= (someFunction(47))


I don't understand. If "variable" is a Public variable in
the class module, then it is a property of the class. The
code in the corresponding PropertySet procedure will be
executed automatically and can perform whatever actions you
want, including calling some other function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top