Variables, Formulas, and the .NET Framework in Visual Basic 2010 Part 2

Formula is a statement that combines numbers, variables, operators, and keywords to create a new value. Visual Basic contains several language elements designed for use in formulas. In this section, you’ll practice working with arithmetic (or mathematical) operators, the symbols used to tie together the parts of a formula. With a few exceptions, the arithmetic symbols you’ll use are the ones you use in everyday life, and their operations are fairly intuitive. You’ll see each operator demonstrated in the following exercises.

Arithmetic Operators











Using Parentheses in a Formula
You can use one or more pairs of parentheses in a formula to clarify the order of precedence or impose your own order of precedence over the standard one. For example, Visual Basic calculates the formula

Number = (8 – 5 * 3) ^ 2
 
by determining the value within the parentheses (–7) before doing the exponentiation—even though exponentiation is higher in order of precedence than subtraction and multiplication, according to the preceding table. You can further refine the calculation by placing nested parentheses in the formula. For example,

Number = ((8 – 5) * 3) ^ 2

directs Visual Basic to calculate the difference in the inner set of parentheses first, perform the operation in the outer parentheses next, and then determine the exponentiation. The result produced by the two formulas is different: the first formula evaluates to 49 and the second to 81. Parentheses can change the result of a mathematical operation, as well as make it easier to read.

No comments:

Post a Comment

 

About the Author

My name is Jakfar Zakaria. My friends call me Jakfar. I have lived such a tiring journey, about my education and others. Four years ago, I explore the computer network specializes in Linux Technology. And now I steeped about computer programming. I have little ability in computer programming, I focus on Visual Basic .NET programming language and PHP programming language. It takes a big sacrifice in studying it all, and my teacher is Google! Yups, Google! Google is a good teacher for me.

JOIN THE COMMUNITY!

TAKE A BREAK