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
[code=thinbasic]IF MyVar = 1 THEN
MyFunction_A(Var1, Var2, Var3)
ELSE
MyFunction_B(Var1, Var2, Var3)
END IF[/code]
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:
[code=thinbasic]
CALL "MyFunction_" & IIF$(MyVar = 1, "A", "B") (Var1, Var2, Var3)
[/code]
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
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Bookmarks