Tải bản đầy đủ (.pptx) (67 trang)

microsoft visual basic 2015 chapter 04

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.5 MB, 67 trang )

Microsoft Visual Basic 2015

CHAPTER FOUR

Variables and
Arithmetic Operations


4

Objectives

►Create, modify, and program a TextBox object
►Use code to place data in the Text property of a Label object
►Use the AcceptButton and CancelButton properties
►Understand and declare String and Numeric variables
►Use assignment statements to place data in variables

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

2


4

Objectives

►Use literals and constants in coding statements


►Understand scope rules for variables
►Convert string and numeric data
►Understand and use arithmetic operators and arithmetic operations

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

3


4

Objectives

►Format and display numeric data as a string
►Create a form load event
►Create a concatenated string
►Debug a program

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

4


4


Introduction

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

5


4

TextBox Objects

►With Visual Studio open, the Desktop application created, and the [Design] tabbed
page visible, point to the TextBox .NET component in the Toolbox

►Drag the TextBox .NET component onto the Windows Form object at the desired
location

►When the upper-left corner of the pointer is located where you want the TextBox
object’s upper-left corner, release the left mouse button

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

6



4

TextBox Objects

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

7


4

Sizing and Positioning a TextBox Object

► Select the TextBox object. Select the (Name) property and type the desired name. Scroll in the
Properties window until the Text property is visible and then tap or click the right column for the Text
property

► Type the maximum number of characters the user normally will enter into the text box and then
press the ENTER key. Programmers often use the digit 8 in this situation because it is wider than
other digits

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.


8


4

Sizing and Positioning a TextBox Object

►Using the Properties window, change the Font property to the correct font and font
size. Then, drag the right edge of the TextBox object and resize it to be slightly wider
than the entry

►To horizontally align the text in the label and the text in the text box, drag the text box
up until a red snap line indicates the bottoms of the text are aligned. Then, release the
left mouse button

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

9


4

Sizing and Positioning a TextBox Object

Chapter 4: Variables and Arithmetic Operations


© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

10


4

Aligning Text in a TextBox Object

► Select the TextBox object. In the Properties window, scroll until the TextAlign property is visible, tap
or click the TextAlign property in the left column, and then tap or click the list arrow in the right
column of the TextAlign property

► Tap or click the desired alignment option in the TextAlign property list
► Because the TextBox object is sized properly, remove the digits in the TextBox object. Select the
characters in the Text property, press the DELETE key on your keyboard, and then press the
ENTER key

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

11


4

Aligning Text in a TextBox Object


Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

12


4

Creating a MultiLine Text Box

►Select the TextBox object, tap or click the Action tag, and then point to the MultiLine
check box

►Tap or click the MultiLine check box

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

13


4

Creating a MaskedTextBox Object


Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

14


4

Creating a MaskedTextBox Object

►Drag a MaskedTextBox .NET component from the Toolbox to the Windows Form
object. Then, tap or click the Action tag on the TextBox object and point to the Set
Mask command

►Tap or click Set Mask on the MaskedTextBox Tasks list and then tap or click the
desired mask description in the Input Mask dialog box

►Tap or click the OK button in the Input Mask dialog box and then tap or click anywhere
in the Windows Form object

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

15



4

Creating a MaskedTextBox Object

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

16


4

Label Objects

►Drag a Label object onto the Windows Form object to the correct location. Enter the
desired name for the label. Change the label to the appropriate font size. In the Text
property for the Label object, enter the maximum number of characters that will
appear in the label during execution of the program

►Drag the Label object up until the red snap line appears. Then release the Label
object

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

17



4

Label Objects

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

18


4

Accept Button in Form Properties

►After the Button objects are added, tap or click a blank area in the Windows Form
object to select it. Scroll in the Properties window until the AcceptButton property is
visible. Tap or click the AcceptButton property name in the left column and then tap or
click the AcceptButton property list arrow in the right column

►Tap or click the desired button in the AcceptButton property list

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.


19


4

Accept Button in Form Properties

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

20


4

Cancel Button in Form Properties

►When the user presses the esc key, the event handler processing will be executed for
the button identified as the Cancel button

►Tap or click a blank area in the Windows Form object to select it
►Tap or click the CancelButton property name in the left column in the Properties
window for the Windows Form object, and then tap or click the CancelButton list arrow

►Tap or click the desired button name in the CancelButton property list

Chapter 4: Variables and Arithmetic Operations


© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

21


4

Visual Studio Preparation for Code Entry

►With the Toolbox visible, tap or click the Toolbox Close button. The Toolbox closes
and the work area expands in size. To display the Toolbox after it has been closed,
tap or click the View menu and then tap or click Toolbox

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

22


4

String Data Type

► A String data type can store any character available on the computer
► The data type for the value the user enters in a TextBox object and that is stored in the Text property
of the TextBox object is string


► A variable is a named location in RAM where data is stored
► A String variable is a named location in RAM that can store a string value

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

23


4

String Data Type

Chapter 4: Variables and Arithmetic Operations

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.

24


4

Assignment Statements

►One method used to place data in the variable is an assignment statement

Chapter 4: Variables and Arithmetic Operations


© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible
website, in whole or in part.

25


×