Mathematical Functions

Roots

To find the square root of a number in Visual Basic, use the Sqr function. It's syntax is very simple:

Sqr(9) ' returns 3

One function that might not be quite so obvious is how to calculate the nth root of a number. To do this, all you need to do is use the following syntax:

nNumber ^ (1 / nRoot)

So, if you wanted to find the cubed root of 8 (ie root 3), all you need to do is

8 ^ (1 / 3)

and, if you wanted to find root 4 of 12, use

12 ^ (1 / 4)

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay