Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable.

Similar presentations


Presentation on theme: "Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable."— Presentation transcript:

1

2 Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable must be on the left and the expression on the right.

3 Chapter 3 - Visual Basic Schneider Assignment Statement: The statement var = expr assigns the value of the expression to the variable tax = 0.02 * (income - 500 * dependents) sum = 2 + x + 4.6 + y

4 Chapter 3 - Visual Basic Schneider Valid Numeric Variable Names: timeElapsed taxRate speed n celsius

5 Chapter 3 - Visual Basic Schneider Invalid Numeric Variable Names: maximum/average 1stChoice square yard

6 Chapter 3 - Visual Basic Schneider Valid Assignment Statements count = count + 1 num = 5 count = count + num /2

7 Chapter 3 - Visual Basic Schneider Invalid Assignment Statements 10 = count count + 1 = count

8 Chapter 3 - Visual Basic Schneider Visual Basic Print Statement Print is a method used to display data on the screen or printer. Can be used to display values of variables or expressions

9 Chapter 3 - Visual Basic Schneider Examples of Print Statements Private Sub cmdCompute_Click() picResults.Print 3 + 2 picResults.Print 3 - 2 picResults.Print 3 * 2 picResults.Print 3 / 2 picResults.Print 3 ^ 2 picResults.Print 2 * (3 + 4) End Sub

10 Chapter 3 - Visual Basic Schneider Examples of Print Statements picOutput.Print speed picOutput.Print taxRate picOutput.Print “Class average is”; total / 3

11 Chapter 3 - Visual Basic Schneider Examples of Print Statements x = 15 y = 5 picOutput.Print (x + y) / 2, x / y Output: 103

12 Chapter 3 - Visual Basic Schneider String Constants: A sequence of characters treated as a single item The characters in a string must be surrounded by double quotes (“ ”)

13 Chapter 3 - Visual Basic Schneider Valid String Constants “A rose by any other name” “9W” “134.23” “She said, ‘stop, thief!’ ”

14 Chapter 3 - Visual Basic Schneider Invalid String Constants ‘Down by the Seashore’ “134.24 “She said, “Stop, thief!””

15 Chapter 3 - Visual Basic Schneider String Variables A string variable stores a string. The rules for naming string variables are identical to those for naming numeric variables. When a string variable is first declared, its value is the empty string.

16 Chapter 3 - Visual Basic Schneider String Variable Example Private Sub cmdShow_Click() picOutput.Cls phrase = "win or lose that counts." picOutput.Print "It's not whether you "; phrase picOutput.Print "It's whether I "; phrase End Sub

17 Chapter 3 - Visual Basic Schneider Concatenation Two strings can be combined by using the concatenation operation. The concatenation operator is the ampersand (&) sign.

18 Chapter 3 - Visual Basic Schneider Examples of Concatenation: strVar1 = “Hello” strVar2 = “World” picOutput.Print strVar1& strVar2 txtBox.Text = “32” & Chr(176) & “ Fahrenheit”

19 Chapter 3 - Visual Basic Schneider Declaring Variable Types Use the Dim statement to declare the type of a variable. Examples: Dim number As Integer Dim flower As String Dim interestRate As Single


Download ppt "Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable."

Similar presentations


Ads by Google