excel vba - Class of a Class -
excel vba - Class of a Class -
i'm getting killed trying create class of class. have shopped around site , seen several examples maybe because 1:43 having hard time understanding them.
i able utilize class automate huge info entry project @ work. created class called catdist category distribution of types of agricultural products company manufacture or sell.
catdist contains 6 properties: private selfworth string private q1 double private q2 double private q3 double private q4 double private activated boolean
they have standard , allow codes.
there 48 possible categories. have module creates 48 instances of them 48 different values selfworth (e.g "cottonseed", or "maize" etc), , sets q1 through q4 0 . module worked userform type in values , nail enter. if saw had entered value within particular textbox (yes there 48x4 textboxes) set activated true , changes relevant q's values entered.
what want now.
it great success. want create class called "distributor". each distributor class have 4 collections have catdist objects. can create distributor class. can create catdist class. love of god can not figure out way set corresponding distributor catdist property catdist value used in set method.
sub testregist() dim registrant testregistrant set registrant = new testregistrant registrant.registnum = "z000123" 'msgbox (registrant.registnum) dim cowmilk testcatdist set cowmilk = new testcatdist cowmilk.selfworth = "cow milk" cowmilk.distribution = 4.6 registrant.testcat = cowmilk debug.print registrant.testcat.selfworth end sub
catdist class
private pselfworth string private pdistribution double public property selfworth() string selfworth = pselfworth end property public property allow selfworth(name string) pselfworth = name end property public property distribution() double distribution = pdistribution end property public property allow distribution(dist double) pdistribution = dist end property
registrant a.k.a distributor class
private pregistnum string private pcatdist testcatdist public property registnum() string registnum = pregistnum end property public property allow registnum(registration string) pregistnum = registration end property public property testcat() testcatdist testcat = pcatdist end property public property allow testcat(cat testcatdist) set pcatdist = new testcatdist pcatdist = cat end property
the problem see using let
instead of set
. in vba utilize set
when assigning objects.
when write registrant.testcat = cowmilk
(in sub
), testcat = pcatdist
(in getter of testregistrant.testcat
) , pcatdist = cat
(in setter of testregistrant.testcat
) implicitly using let
(it's if had written let registrant.testcat = cowmilk
) instead of (explicitly) using set
.
so, if write set registrant.testcat = cowmilk
in test sub
, set testcat = pcatdist
in getter , set pcatdist = cat
in setter should go.
also, in same setter, initialization of pcatdist
isn't needed since passing cat
in next line.
and, @gserg (thank you) says, signature of setter should public property set testcat(cat testcatdist)
instead of public property let
.
class excel-vba
Comments
Post a Comment