vba - How can I pass optional arguments on to another function which has optional arguments -
vba - How can I pass optional arguments on to another function which has optional arguments -
i have function called myfunction. has 10 optional arguments. calls function called myotherfunction has same 10 optional arguments.
so let's phone call myfunction argument one. how phone call myotherfunction using argument 1 when don't know of 10 optional arguments have been passed?
i can't ret_value=myotherfunction(arg1:=argumentone) because there between 1 , 10 arguments need pass. if used 2 arguments have ret_value=myotherfunction(arg1:=argumentone, arg2:=argumenttwo) 1 time again @ run time don't know arguments have been passed myfunction. there way parse function call?
just pass arguments along chain. simplistic example:
sub foo() phone call bar("test") end sub sub bar(sone string, optional stwo) phone call foobar(sone, stwo) end sub sub foobar(strone string, optional strtwo) if ismissing(strtwo) msgbox strone else msgbox strone & "- " & strtwo end if end sub note: ismissing in foobar indicate each routine needs test optional arguments before doing them. perhaps clearer illustration of passing them on is:
sub foo() ' note 1 parameter provided phone call bar("test") end sub sub bar(sone string, optional stwo, optional sthree, optional sfour) ' still pass parameters if got 1 phone call foobar(sone, stwo, sthree, sfour) end sub sub foobar(strone string, optional strtwo, optional strthree, optional strfour) ' code here end sub vba function excel-vba argument-passing
Comments
Post a Comment