excel - VBA: instantiate class A in a property of class B -
i beginner @ excel vba oop , need help putting class instance property property of class. have way makes sense me not work. i'm not sure if syntax/structure error, or if i'm missing mark on entirely. here simplified illustration illustrates problem:
class has property string value.
class b has property holds instance of class a, , property takes string parameter , passes class a's property.
class a
private strprop string public property allow prop(sprop string) strprop = sprop end property
class b
private clsa new classa '''different attempts of same method: public property allow classa(strnamea string) clsa.prop = strnamea end property 'public property set classa(strnamea string) ' clsa.prop = strnamea 'end property 'public property set classa(strnamea string) ' ' dim xclsa classa ' set xclsa = new classa ' ' xclsa.name = "foobar" ' clsa = xclsa ' 'end property ' public function message() msgbox(clsa.prop) end function
module (the classes in action)
dim xclassb classb set xclassb = new classb xclassb.classa("foobar") xclassb.message 'should display foobar
the error get:
"i still compile error: definitions of property procedure same property inconsistent or property procedure has optional parameter, paraarray, or invalid set final parameter"
class a
private strprop string public property allow prop(sprop string) strprop = sprop end property public property prop() string prop = strprop end property
classb:
private clsa new classa public property set classa(strnamea string) clsa.prop = strnamea end property public function message() msgbox(clsa.prop) end function
...and add together get
prop
in classa
excel vba oop
No comments:
Post a Comment