excel - Argument not optional error when returning dictionary -
i have following code in vba , i'm trying capture dictionary object returned first function parents in line says "set parents = parents()" keep getting argument not optional error.
everyone on internet says it's because set keyword missing in case isn't. appreciated, thanks!
public function parents() dictionary dim filenum integer dim dataline string dim filepath string set parents = new dictionary filepath = application.activeworkbook.path & "\parents.txt" filenum = freefile() open filepath input #filenum while not eof(filenum) line input #filenum, dataline parents.add dataline, 1 wend end function public sub computechanges() . . dim parents dictionary, adjustments dictionary, inner dictionary, changes dictionary set parents = parents() . . end sub
i suggest changing function sub , passing pre-declared dictionary object in parameter.
public sub constructparents(dprnts dictionary) dprnts.removeall dprnts.comparemode = textcompare dprnts.add key:="joe & jill", item:=100 dprnts.add key:="sam & sally", item:=200 dprnts.add key:="dave & debbie", item:=300 dprnts.add key:="bob & jane", item:=400 debug.print dprnts.count end sub public sub computechanges() dim dparents new dictionary, vkey variant constructparents dparents 'optionally use if makes more sense 'call constructparents(dparents) each vkey in dparents debug.print "key: " & vkey & ", item: " & dparents.item(vkey) next vkey end sub
i've simplified code in order did not have duplicate environment hope can transcribe method own purposes.
Comments
Post a Comment