vba - edit Value in Collection - variable Function ...(?) -
i need help. want change class value within collection, change “variable”.
cadmin = xy ccheckdate=yz cpruefstate= abc colsomename.add classname, key1
i save collection (colsomename). on form, on event raised searched key in collection , current value changed.
in class set values (for example)
sub checkout() .. editincollection colsomename, „stackover“ . . . public function editincollection( _ byref col collection, _ byref elem string) boolean on error goto ende if isempty(col(elem)) msgbox " element: " & col(elem) & „ not exits!", _ vbcritical = vbokonly, "s o r r y " exit function end if`enter code here` isincollection = (err.number = 0) ' col(elem).cadmin =environ("username") col(elem).ccheckdate = date col(elem).cpruefstate= true ' exit function ende: isincollection = false end function
it works perfect. use funkion different classes / collection. possiple? my idear is
public function editincollection( _ byref col collection, _ byref elem string, clsvalue variant(?), newvalue variant) boolean dim …. each xall in col(elem) if xall = clsvalue clsvlaue = newvalue end if exit next end function
but doesn’t work. how can realize this
you can use callbyname
access object's property using name of property:
clstest: simple class testing purposes...
option explicit public testproperty string
example code:
sub tester() dim o new clstest, col new collection o.testproperty = "hello" col.add o, "key1" debug.print "before", o.testproperty '>>> hello 'update property named "testproperty" "i updated" debug.print "updated?", editincollection(col, "key1", _ "testproperty", "i updated") '>>> true debug.print "after", o.testproperty '>>> updated end sub function editincollection(col, key, propname, newvalue) dim o object, rv boolean on error resume next set o = col(key) 'is there object key? on error goto 0 if not o nothing 'object found in collection: update ' property in "propname" "newvalue" callbyname o, propname, vblet, newvalue rv = true end if editincollection = rv 'return success or failure end function
if wanted update multiple properties adapt function accept array of property names , array of new values third , fourth parameters.
Comments
Post a Comment