200 likes | 207 Views
Learn about numbers, arithmetic operations, scientific notation, variable declarations, built-in functions, error types, and more in VB.NET. Explore numerical literals, precedence, scientific notation, display methods, variable rules, and error handling.
E N D
Numbers • Arithmetic Operations • Display numbers in VB.NET • Variables • Built_in Functions • Three types of errors Numbers
Arithmetic Operations • Numbers are called numeric literals • Five arithmetic operations in VB.NET • + addition 3 + 2 • - subtraction 3 - 2 • * multiplication 3 * 2 • / division 3 / 2 • ^ exponentiation 3 ^ 2 Numbers
Precedence of Arithmetic operation Level of precedence: () Inner to outer,left to right ^ Left to right in expression * / Left to right in expression + - Left to right in expression Numbers
Scientific Notation • Scientific notation represents a number by using power of 10 to stand for zeros In VB.Net b • 10 ris written as bEr Numbers
Scientific Notation • r is two digit number preceded by plus sign if r is positive and by a minus sign if r is negative 10 –2010 ^ - 20 1E-20 1.2 • 10 13 1.2 * 10 ^ 13 1.2E+13 • VB.NET’s choice of whether to display a number in a scientific or standard form depends on the magnitude of the number Numbers
Display numbers • One way to show numbers on screen is to display them in a list box. lstNumbers.Items.Add(n) - Display number n as the last item in the list box lstNumbers.Items.Clear() - Erase all the items in the list box Numbers
Demonstration • List a set of numbers in a list box. Numbers
Variables • A variable is a name that is used to refer to an item of data. The value assigned to the variable may change. • Up to 16,838 characters long • Begin with a letter or an underscore • Consist of only letters,digits and underscores • A Variable name is written in lowercase letters except for the first letters of additional words, such as costOfIT201. Numbers
Data Type Numbers
Variable Declaration • Declaration: Dim varName As dataType Variable name Data type Const constantName As dataType = value Variable that can’t change Numbers
Variable Declaration • Dim declares a variable named varName to be of type dataType • Dim causes computer to set aside a location in memory with the same name varName • Dim also put the number zero in that memory location if varName is a numberic variable Numbers
Multiple Declarations • multiple-declaration statements : Dim a, b As Double Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5 Numbers
Variable Initialization • Numeric variables are automatically initialized to 0: Dim varName As Double • To specify a nonzero initial value Dim varName As Double = 50 Numbers
Assignment statement • Assignment:(n is a literal) varName = n varName = expression Numbers
Rules for assigning variables • Assign Integer, Long data type to a variable to store whole numbers • Assign Single, Double to a variable to store decimal fraction • Assign String to a variable to store a list of characters • Assign Boolean data type to a variable whose value will be True or false • Assign Date data type to a variable to store date and time information • Assign Object data type to a variable to store reference to an object • Choosing the data type in each group depending on the size o Numbers
Increment variable value • To add 1 to the numeric variable var var = var + 1 • Or as a shortcut var +=1 Numbers
Built-in Functions • Functions associates with one or more values and returns a value(output) • Math.sqrt(n): Returns the square root of n. Math.Sqrt(9) is 3 • Int(n): Returnsgreatest integer less than or equal to n Int(9.7) is 3 Numbers
Built-in Functions • Math.Round(n, r): • number n rounded to r decimal places Math.Round(2.317,1) is 2.3 Math.Round(2.7) is 3 • When n is halfway between two successive whole number, then it rounds to the nearest even number Math.Round(2.5) is 2 Math.Round(3.5) is 4 Numbers
Three Types of Errors • Syntax error – grammatical errors misspellings, omissions,incorrect punctuation • Run-time error occurs when program is running • Logic error program doesn’t perform as it is intended Numbers