PDA

View Full Version : CALL keyword with function name as string expression



ErosOlmi
07-09-2006, 16:16
I recently had the need to execute 2 functions with the same parameters but different behave depending on some variable data.

At first I started with a natural

IF MyVar = 1 THEN
MyFunction_A(Var1, Var2, Var3)
ELSE
MyFunction_B(Var1, Var2, Var3)
END IF

but later I remembered that CALL keyword can be used to execute a function whose name is computed as sting expression. So the above code can be changed to:


CALL "MyFunction_" & IIF$(MyVar = 1, "A", "B") (Var1, Var2, Var3)


Maybe CALL method is more cryptic but can save some code in special situation, and because scripts are parsed and interpreted, saving code means saving execution time.

Ciao
Eros