Download presentation
Presentation is loading. Please wait.
Published byClare Banks Modified over 9 years ago
1
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions
2
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 2 Objectives Use the RadioButton and GroupBox controls Use the Layout toolbar to size and align controls Set a default button on a form Lock controls on a form Declare variables and constants
3
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 3 Objectives Use variables and constants within code Describe Visual Basic.NET data types Convert between data types Code a form Load event procedure Use the Option Strict statement
4
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 4 Objectives Use arithmetic expressions Describe the order of operator precedence in code Use the Pmt function Use the Format$ function
5
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 5
6
6 Program Development
7
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 7 Starting the Project and Creating the User Interface Start Visual Basic.NET and click the New Project button on the Start Page Click Create directory for Solution, and double- click the text, WindowsApplication1, in the Name box. Type Automobile Loan Calculator in the Name box Click the Browse button. If necessary, click 3½ Floppy (A:) in the Look in box, click Chapter4, and then click Open Click the OK button
8
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 8 Setting Form Properties and Adding Controls
9
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 9 Setting Form Properties and Adding Controls Add three Label controls, two NumericUpDown controls, one TextBox control, and two Button controls
10
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 10 Adding a GroupBox Control to a Form Add the GroupBox control by clicking the GroupBox button in the Toolbox window and drawing the GroupBox1 control on Form1, as shown below
11
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 11 Adding RadioButton Controls to Create a Group of Controls Drag the RadioButton button from the Toolbox window to the top of the GroupBox1 control. Be sure to release the mouse button while the mouse pointer is positioned within the borders of the GroupBox1 control Repeat this step to create two more RadioButton controls
12
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 12 Changing Control Properties Change the properties of the Label, NumericUpDown, TextBox, and Button controls according to Table 4-4 on page 4.14 and 4.15 in the text
13
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 13 GroupBox Control Properties
14
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 14 RadioButton Control Properties
15
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 15 Selecting Multiple Controls and Using the Align Rights Button Select the Label2 control, which has the Text property value of Current interest rate (%) Use the middle sizing handle on the left or right side of the control to size the control so that the text within the control displays on a single line. Press and hold down the CTRL key and then click the other two Label controls on the form
16
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 16 Selecting Multiple Controls and Using the Align Rights Button Click the Align Rights button on the Layout toolbar and then click the Make Vertical Spacing Equal button on the Layout toolbar. Align the controls as shown below:
17
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 17 Sizing and Aligning Controls Make Same Size button Increase Horizontal Spacing button Center Horizontally button Align Lefts button Align Tops button Make Vertical Spacing Equal button
18
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 18 Verify the Size and Position of Controls
19
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 19 Setting the Default Button on a Form Pressing the ENTER key is equivalent to clicking the button Select the AcceptButton property in the properties window for Form1 to btnComputePayment
20
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 20 Locking Controls on a Form Disallows the ability to move controls or modify control sizes on a form during design time Select Form1 Click Format on the menu bar, and select Lock Controls
21
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 21 Declaring Constants and Variables A value is a number or string that programmers use in the code A variable represents a location in computer memory that can change values as the code executes A constant represents a location in computer memory that cannot be changed during execution
22
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 22 Data Types
23
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 23 Declaring Constants
24
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 24 Declaring Constants Double-click the Form1 form in an area that does not contain a control. When the code window displays, click 189 Enter the seven lines of code below, and press the ENTER key after entering the last line
25
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 25 Coding a Form Load Event Procedure Executes when the form first loads into memory Click line 198 in the Form1_Load event procedure and enter the two lines of code below. Do not press the ENTER key after entering the second line
26
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 26 Coding the btnReset_Click Event Procedure Click the Form1.vb[Design] tab and then double-click the btnReset control. Enter the 7 lines of code below. Do not press the ENTER key when finished
27
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 27 Using the Option Strict Statement Instructs Visual Basic.NET to force you to ensure that all assignment statements use the same data type on both sides of the assignment In the code window on line 1, type Option Strict On
28
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 28 Declaring Global Variables
29
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 29 Declaring Global Variables Click the end of line 195 and then press the ENTER key. Enter the line of code below, and do not press the ENTER key
30
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 30 Coding the Event Procedures for the RadioButton Controls Enter the code below on their respective lines:
31
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 31 Declaring Local Variables Click the Form1.vb[Design] tab and then double-click the btnComputePayment control. Enter the code below in the code window. Do not press ENTER after entering the last line
32
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 32 Converting Data Types Press the ENTER key twice. Enter the line of code below and do not press ENTER
33
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 33 Numeric Expressions and Operator Precedence
34
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 34 Construction of Error-Free Numeric Expressions
35
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 35 Coding an Expression to Calculate a Monthly Interest Rate Press the ENTER key twice. Enter the lines of code below and do not press the ENTER key
36
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 36 Intrinsic Functions Ddb() Fv() Lpmt() Lrr() Mirr() Nper() Npv() Ppmt() Pv() Rate() Sin() Syd()
37
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 37 The Pmt Function
38
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 38 Using the Pmt Function Press the ENTER key twice. Enter the lines of code below and do not press the ENTER key
39
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 39 The Format$ Function
40
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 40 Using the Format$ Function Press the ENTER key. Enter the lines of code below and do not press the ENTER key
41
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 41 Finishing the Project Save the project –Click the Save All button on the Standard toolbar Test the project using test data and verify your output Document the application using your knowledge from Chapter 2 Quit Visual Basic.NET
42
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 42 Summary Use the RadioButton and GroupBox controls Use the Layout toolbar to size and align controls Set a default button on a form Lock controls on a form Declare variables and constants
43
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 43 Summary Use variables and constants within code Describe Visual Basic.NET data types Convert between data types Code a form Load event procedure Use the Option Strict statement
44
Chapter 4: Working with Variables, Constants, Data Types, and Expressions 44 Summary Use arithmetic expressions Describe the order of operator precedence in code Use the Pmt function Use the Format$ function
45
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Complete
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.