You need to specify the operator when calling the function. The function itself should check what operator (-, +, / or *) is needed and act accordingly. The outcome can be stuffed into a variable with the same name as the function so you get some data from the function.

Best practice would be to dim all used variables inside the function except the ones used as parameters for the function. A check if all parameters are like they should be (integer and the used operators) would also be great to avoid unexpected results like add 1 to 8 resulting in 81 instead of 9.


If you are totally stuck and there is absolutely no way out check out the spoiler I added. Working example and not best practice coding but it will get you somewhere. Try to write it yourself first ;\)

Warning, Spoiler:

 Code:
Break on

$var2 = Math(1,8,"add")
? "var = " + $var2


Function Math($num1, $num2, $operator)
	
Select
	Case $operator = "add"
		$math = $num1 + $num2
	Case $operator = "divide"
		$math = $num1 / $num2
	Case $operator = "multiply"
		$math = $num1 * $num2
	Case $operator = "subtract"
		$math = $num1 - $num2
EndSelect
		
EndFunction

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.