[VBA] passing functions

  • Thread starter Thread starter Madla
  • Start date Start date
M

Madla

Can I pass a function into a sub routine as in JavaScript? Or create a
function on the fly?

I have a routine that creates various shapes by calling a subroutine
that's specific to the shape.. Each of these subroutines calls again a
another subroutine.

sub createSlideObjects(objType as integer)
select case objType
case 1
shapeArray = array(createShape1, createShape2...)
case 2
shapeArray = array(createShape1, createShape3...)
end select
end sub

sub createShape1()
with ...addShape(msoShapeRectangle, 0, 0, 100, 100)
setShape1(...)
end with
end sub

I want to refactor the "createShapex" routines into one single routine (
by passing the type of shape into it) but still keep the "setroutines"
as they are. If I can avoid it, I don't want to setup another select
statement inside the refactored "crateShapex" routine to figure out
which "setShapex" routine to call.
So is it either possible to pass the function to be called into the
"createShapex" routine or create the call to the function from
evaluating a string into code?

Thanks...martin
 
Back
Top