Chapter 6. Numbers and Math

Introduction

Visual Basic is now completely on a par with C# and other languages in its scientific, engineering, and financial number-crunching capabilities. This chapter demonstrates how easy it is to develop very fast and powerful, yet easy-to-read code for advanced number-crunching applications. Some of the recipes will appeal to almost all developers, such as those demonstrating rounding, the new unsigned integers, and the new Decimal numbers that are suitable for the most demanding financial calculations. Other recipes will appeal to the many scientist and engineer types searching for 21st century updates for FORTRAN, programmable calculators, and Excel.

6.1. Using Compact Operator Notation

Problem

You want to write compact, efficient code using the latest syntax available for assignment operators.

Solution

Sample code folder: Chapter 06\CompactOperators

Visual Basic 2005 now lets you use the same compact assignment notation for some math operations that has been used in the C and C# languages for many years.

There are several compact assignment operators, and they all work the same way. The variable to the left of the operator is used both as a source value and as a destination for the results of the operation. The operators are listed in Table 6-1.

Table 6-1. Compact assignment operators

Operator

Description

^=

Exponentiation

*=

Multiplication

/=

Division

\=

Integer division

+=

Addition

-=

Subtraction

<<=

Shift left

>>=

Shift right

&=

Comparison

Discussion ...

Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.