Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.

Similar presentations


Presentation on theme: "Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic."— Presentation transcript:

1 Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic

2 Variables Holds data Controls for Design Programming, Variables for Code Programming Text Property  Data  Variable Manipulate data w/o showing to users Store data w/o adding or using controls Hold numbers, data & time, text, and etc. Continue 

3 One type of variable can take the same type of data. E.g.  intCount = 15 (OK)  intCount = “Pat” (not OK)  intCount = “15” (not OK) Must be declared. E.g.  Dim intCount As Integer  Dim sngPrice As Single Continue 

4 Steps of Using Variables Declare Input: Assign a value by reading in from a control or other source Process: Use or manipulate Output: Put the value to a control or other object

5 Example 1: Dim intTotal As Integer intTotal = Val(txtTotal.Text) intTotal = intTotal + 10 txtTotal.Text = Str(intTotal)

6 Example 2: Dim intTotal As Integer Dim intExtra As Integer intTotal = Val(txtTotal.Text) intExtra = 10 intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)

7 Example 3: Dim intTotal As Integer Dim intExtra As Integer = 10 intTotal = Val(txtTotal.Text) intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)

8 Data Types of Variables Data TypeMemory AllocationValue Range Boolean2 bytesTrue or False. Char2 bytes0 through 65535 (unsigned). Date8 bytes0:00:00 on January 1, 0001 through 11:59:59 PM on December 31, 9999. StringDepends on platform0 to approximately 2 billion Unicode characters. Short2 bytes-32,768 through 32,767. Integer4 bytes-2,147,483,648 through 2,147,483,647. Long8 bytes-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Single4 bytes-3.4028235E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.4028235E+38 for positive values. Double8 bytes-1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values; 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values. Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest nonzero number is +/-0.0000000000000000000000000001 (+/-1E-28).

9 Integer Stored as 32-bit (4-byte) integers ranging in value from -2,147,483,648 through 2,147,483,647. Provides optimal performance on a 32-bit processor, as the smaller integral types are slower to load and store from and to memory. You can convert the Integer data type to Long, Single, Double, or Decimal without encountering a System.OverflowException error.

10 Single Stored as IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from - 3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single- precision numbers store an approximation of a real number. Can be converted to the Double or Decimal data type without encountering a System.OverflowException error.

11 String Stored as sequences of 16-bit (2-byte) numbers ranging in value from 0 through 65535 Each number represents a single Unicode character. A string can contain up to approximately 2 billion (2 ^ 31) Unicode characters The first 128 code points (0–127) of Unicode correspond to the letters and symbols on a standard U.S. keyboard The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions The remaining code points are used for a wide variety of symbols

12 Prefixes for Variables Data TypePrefixData TypePrefix BooleanblnIntegerint BytebytLonglng CurrencycurShortsht Date(time)dtmSinglesng DoubledblStringstr

13 Arithmetic Operators OrderOperatorMathematical OperationExample 1( )Parentheses 2^ExponentiationCubicSpace = Length ^ 3 8 = 2 ^ 3 3-Negation- Num1 4* or / Multiplication Division Total_Sales = Unit_Price * Count ClassAve = TotalScores / NumOfStudents 5\Integer Division (DIV). The whole number portion of the answer in a division. The decimal position is dropped. CarsCanFitIn = AreaOfLot \ CarDim 10 = 215 \ 20 15 is leftover Continue 

14 OrderOperatorMathematical OperationExample 6MODInteger Remainder Division. The whole number portion of a remainder in a division. If the divider is greater than the number it is dividing, then the number become the remainder of the MOD division. BoothSpace = 3 MOD 10 3 = 3 MOD 10 7+ or - Addition Subtraction Total = Num1 + Num2 Profit = Sales - Expenses &String concatenationFullName$ = First$ & Last$

15 Using Debugger Demo


Download ppt "Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic."

Similar presentations


Ads by Google