Is it possible in the VBA language to build a degree in a degree without using the exercise operation, but only with the for Next cycle? If so – how?
Answer 1, Authority 100%
function fexp_ (dnum as double, optional exp as long = 2) as double Dim X AS Double: X = DNUM DIM I AS LONG For i = 2 to exp: x = x * dnum: next i Fexp_ = X. End Function.
In the cell:
= fexp_ (4; 5)
or call from the procedure:
sub test () Debug.print Fexp_ (4, 5) End Sub.
In such a record, the result = 4 ^ 5. Without an indication of the degree, the number is erected into square
= fexp_ (4)
Instead of the number, you can refer to the cell with a number.
As already mentioned in the comments, it is possible for a whole degree. Here is an example for a positive degree.
Considering that 2 ^ 3 = 2 * 2 * 2 You can write such a code:
dim base as integer = 2 Dim Number AS Integer = 1 Dim Power AS Integer = 3 Dim I AS Integer For i = 1 to Power Number * = Base NEXT I. Console.WriteLine (Number)