Home computickets Evaluate a number into a degree without using the exercise operation using...

Evaluate a number into a degree without using the exercise operation using the For Next cycle. VBA

Author

Date

Category

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%

vba-udf

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.


Answer 2

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)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions