Function powBINit(ByVal a, ByVal b) 'function to calculate a to the power of b using iteration 'and binary powering 'function has two inputs (a,b) and one output (y) 'b must be a positive integer Dim y As Double 'The answer (y) might be big so we should use 'Double instead of Integer y = 1.0 Do While b > 0 If b mod 2 then 'we know here that b is odd: so 'write a^b as (a)(a^(b-1)) y=y*a b=b-1 Else 'we know here that b is even: so 'write a^b as (a^2)^(b/2) a=a*a b=b/2 End If Loop Return y 'You MUST include a Return statement in every function End Function