Mathematical Functions

Standard Math Functions

Math Function Evaluates:

Less than?

<>

Not

>

Greater than?

+

Add

*

Multiply

()

Math Brackets

-

Subtract

^

Power of
/ Divide

You can use these as if you were using a calculator. The standard rule applies that division and multiplication are calculated before addition and subtraction, unless you use brackets. For example,

3 + 2 * 5 = 13   ' 2 multiplied by 5 is 10, then, add 3 which gives us 13
(3 + 2) * 5 = 25 ' 3 and 2 equals 5, and then multiply the 5 by 5, which gives us 25

The noticeable differences between a calculator and Visual Basic is that the signs used are slightly different. Look at the table below to see what I mean.

For example, the following code performs a number of functions on a number, and displays a message box with the result

' Multiply
Msgbox "Multiply 1 * 32: " & 1 * 32
' Divide
Msgbox "Divide 32 / 12: " & 32 / 12
' Power of 3
Msgbox "Power 9 ^ 3: " & 9 ^ 3
' Greater than 100?
Msgbox "234 greater than 100? " & 234 > 100

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.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout