40 likes | 160 Vues
This document provides a detailed overview of variable declarations and arithmetic operations in programming, specifically focusing on integer and floating-point types. It showcases multiple examples, including the use of constants, user inputs, and calculations involving integers and doubles. Key sections illustrate how to declare variables, perform simple arithmetic operations, and handle user inputs effectively. Readers will gain hands-on insights into using variables for storing values and computing results in a structured manner, enhancing their programming skills.
E N D
Variable Exercises Chapter 3 Chapter 3 Part 2
Example 1 Const intTWO As Integer = 2Const intFIVE As Integer = 5Dim intA As IntegerDim intB As IntegerDim intC As IntegerintC = intA + intBintB = intB + intTWOintA = intTWO * intFIVEintB = intA – (intTWO + intFIVE)intA = intA + intAintC += intAintB -= intA lblOutput.Text = intB Chapter 3 Part 2
Example 2 Dim sngTestA As Single Dim sngTestB As Single Dim sngTestDifference As Single sngTestA = 2.3456789 sngTestB = 1.2345678 sngTestDifference = sngTestA – sngTestB What would be stored in TestDifference if 3 variables are Decimal? Long? Double? Chapter 3 Part 2
Example 3 'Class-level declaration Dim dblSubtotal as Double 'Event Procedure Private Sub btnFirst_Click…Dim dblAmount As DoubleDim intQuantity As Integer'Code stores user input: 10.50; 3dblSubtotal += (dblAmount*intQuantity) End Sub 'Event Procedure Private Sub btnSecond_Click…Dim dblExtPrice As DoubleDim intQuantity As Integer'Code stores user input: 5.25; 4dblSubtotal += (dblExtPrice * intQuantity) End Sub Chapter 3 Part 2