excel - Class initialization: difference between dim new and set new: attributes don't get updated -
i have class state has methods setstatename (sets name attribute), storebudgetworkbooks (sets , edits collection of strings), storebudgetdatas (sets , edits collection of other objects) , editresultworkbook (opens workbook , puts data collection of objects created storebudgetdatas inside it).
i have main sub makes use of class:
sub startgrabbings() ... statecount = lbound(statenames) ubound(statenames) dim statecopy new state statecopy.setstatename = statenames(statecount) statecopy.storebudgetworkbooks statecopy.storebudgetdatas if statecopy.getemptydata = false call statecopy.editresultworkbook(resultworkbook, rowscount) rowscount = rowscount + 10 end if next ... end sub but when open result workbook see data 1 state instance put under other states' names. can't understand reason of - create new copy of state class object, create , set inner collections , object, put data in result workbook. why data first state (but names other states updated).
however when declare class this, works fine:
sub startgrabbings() ... dim statecopy state statecount = lbound(statenames) ubound(statenames) set statecopy = new state statecopy.setstatename = statenames(statecount) statecopy.storebudgetworkbooks statecopy.storebudgetdatas if statecopy.getemptydata = false call statecopy.editresultworkbook(resultworkbook, rowscount) rowscount = rowscount + 10 end if next ... end sub here class state:
private statename string private budgetworkbooks collection '2014-2017, workbook private allbudgetitems collection '2014-2017, collection of collections of items private emptydata boolean private ratingdatas collection public property let setstatename(value string) statename = value end property ... private sub class_initialize() set budgetworkbooks = new collection set allbudgetitems = new collection set ratingdatas = new collection emptydata = false end sub function storebudgetworkbooks() dim year integer year = 2014 2017 budgetworkbooks.add (getbudgetworkbook(year)) next end function sub storebudgetdatas() ... dim year integer year = 2014 2017 ... allbudgetitems.add getbudgetdata(budgetworkbook, year) ... next ... end sub function getbudgetdata(budgetworkbook workbook, year integer) ... dim budgetitems collection set budgetitems = getbudgetitems(year) dim budgetitem item each budgetitem in budgetitems ... 'set attributes next ... set getbudgetdata = budgetitems end function sub editresultworkbook(resultworkbook workbook, rowscount long) dim integer = 1 dim year integer year = 2014 2017 call fillbudgetresultworkbook(resultworkbook, allbudgetitems(i), _ rowscount, statename, year) = + 1 next end sub sub fillbudgetresultworkbook(resultworkbook workbook, resultcollection variant, _ rowscount long, statename string, year integer) ... dim budgetitem item each budgetitem in resultcollection resultworkbook.worksheets("1").cells(i, 1).value = statename resultworkbook.worksheets("1").cells(i, 2).value = budgetitem.gettitle() resultworkbook.worksheets("1").cells(i, 3).value = budgetitem.getkind() resultworkbook.worksheets("1").cells(i, j).value = budgetitem.getbudgetvalue() ... end sub it looks while state attibutes, statename updated, others, collection of items - allbudgetitems don't... why happen , why second version of startgrabbings fixes it? seems come difference between dim object new objecttype , dim object objecttype, set object = new objecttype thought same thing.
Comments
Post a Comment