Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.

Similar presentations


Presentation on theme: "Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms."— Presentation transcript:

1 Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms

2 Chapter 6: Looping and Multiple Forms 2 Objectives Add additional forms to a project Change the default icon on the title bar of a form Use the ListView controls to display a list of items on a form Use the CheckBox controls in an application Use the Anchor property of controls

3 Chapter 6: Looping and Multiple Forms 3 Objectives Work with Collections in code Code a Do Until loop Code a Do While loop Code a For…Next and a For Each…Next loop Code a concatenation operator

4 Chapter 6: Looping and Multiple Forms 4 Objectives Code a keyboard event Code a form Resize event procedure Work with multiple code windows Specify a Startup object for a project

5 Chapter 6: Looping and Multiple Forms 5

6 6

7 7 Creating the User Interface Open a New Project named Today’s Sales Check in the Chapter6 folder on your Data Disk Set the following properties for your form

8 Chapter 6: Looping and Multiple Forms 8 Creating the User Interface Add a ListView control and three Button controls to your form Select the Icon property in the Properties window Click the Icon property ellipsis button. Select the CHECKMRK file from the C:\Program Files\Microsoft Visual Studio.NET\Common7\Graphics\Icons\Misc folder Click the Open button

9 Chapter 6: Looping and Multiple Forms 9

10 10

11 Chapter 6: Looping and Multiple Forms 11 Changing the Properties of a ListView Control Click the Columns property ellipsis button in the ListView Control Properties window Click the Add button Select the Text property value for the ColumnHeader1 member. Type Item Description as the property value. Select the Width property value for the ColumnHeader1 member. Type 190 as the property value and click the Add button

12 Chapter 6: Looping and Multiple Forms 12 Changing the Properties of a ListView Control Select the Text property value for the ColumnHeader2 member and type Total Sales as the property value. Select the Width property value for the ColumnHeader1 member and type 79 as the property value. Click the Add button. When the ColumnHeader3 member is added, select the Text property value for the ColumnHeader3 member. Type On Sale as the property value and click OK

13 Chapter 6: Looping and Multiple Forms 13 Anchoring Controls Select the three button controls on the form, by holding CTRL while clicking each button Click the button anchor indicator to select it. Click the left and top anchor indicators to deselect them and press ENTER Select lstTodaysSales and click the down arrow in the Anchor property of the Properties window Click the bottom and right anchors to select them, and press ENTER

14 Chapter 6: Looping and Multiple Forms 14 Changing the File Name of a Form Right-click the Form1.vb form in the Solution Explorer window Click the Rename command on the shortcut menu. Type Todays Sales Check Form.vb and press ENTER

15 Chapter 6: Looping and Multiple Forms 15 Adding a Form to a Project and Creating the Interface Right-click the Today’s Sales Check project in the Solution Explorer window and then point to Add on the shortcut menu Click the Add Windows Form command on the Add submenu and select Form1 in the Name text box and then type Add Item Form Click the Open button

16 Chapter 6: Looping and Multiple Forms 16 Creating an Interface on a Newly Added Form Add two Label controls, one TextBox control, one NumericUpDown control, a CheckBox control, and a button control Set the form, label, text box, and NumericUpDowncontrol properties as specified on pages VB 6.31 and VB 6.32

17 Chapter 6: Looping and Multiple Forms 17 CheckBox Control Properties

18 Chapter 6: Looping and Multiple Forms 18 Declaring an Object Using an Object Variable

19 Chapter 6: Looping and Multiple Forms 19 Declaring an Object and Showing a Form Enter the code below, beginning on line 119

20 Chapter 6: Looping and Multiple Forms 20 Looping and the Do Statement

21 Chapter 6: Looping and Multiple Forms 21 The Do While and Do Until Statements

22 Chapter 6: Looping and Multiple Forms 22 The While…End While Statement

23 Chapter 6: Looping and Multiple Forms 23 Implementing a Loop Using a Do Until Statement Enter the following code, starting on line 136

24 Chapter 6: Looping and Multiple Forms 24 Working with Collections in ListView Controls Group of one or more objects that can be accessed and operated on as a single entity

25 Chapter 6: Looping and Multiple Forms 25 Adding Items to a ListView Control Text Property SubItems Property

26 Chapter 6: Looping and Multiple Forms 26 Adding Items to a ListView Control Enter the following code, starting on line 137

27 Chapter 6: Looping and Multiple Forms 27 For…Next Statement Great for counter- controlled loops More efficient than a Do While Loop Easier to read Uses less memory Faster execution

28 Chapter 6: Looping and Multiple Forms 28 The Execution of a For…Next Loop The first time the loop executes, intNumber is initialized at 1 intNumber is compared with 100. Because it is less than or equal to 100, the statements in the For loop are executed Control returns to the For statement, where the value of intCount is incremented by 1

29 Chapter 6: Looping and Multiple Forms 29 The Execution of a For…Next Loop If the value of intCount is less than or equal to 100, execution of the For…Next loop continues When the value of intCount is greater than 100, control transfers to the statement following the corresponding Next statement

30 Chapter 6: Looping and Multiple Forms 30 Exiting a Loop Prematurely – The Exit Statement

31 Chapter 6: Looping and Multiple Forms 31 Nested For…Next Loops

32 Chapter 6: Looping and Multiple Forms 32 Implementing a Loop Using a For…Next Statement

33 Chapter 6: Looping and Multiple Forms 33 Implementing a Loop Using a For…Next Statement Enter the following code, starting on line 150

34 Chapter 6: Looping and Multiple Forms 34 The For Each…Next Statement

35 Chapter 6: Looping and Multiple Forms 35 Coding the String Replace() Method Click line 163 and enter the code below This code replaces the dollar sign in the strItemSales variable with a 0, so that the string can be converted to a number and used in an expression

36 Chapter 6: Looping and Multiple Forms 36 String Manipulation

37 Chapter 6: Looping and Multiple Forms 37 Concatenation Operators

38 Chapter 6: Looping and Multiple Forms 38 Coding a Concatenation Operator Enter the code below, starting on line 164

39 Chapter 6: Looping and Multiple Forms 39 Removing Items from a ListView Control Click the Todays Sales Form.vb[Design] tab in the main work area. Double-click the btnClearList button. When the code window appears, click line 181 and then enter the code below

40 Chapter 6: Looping and Multiple Forms 40 Keyboard Events Click the Object box arrow in the code window Click lstTodaysSales in the Object list. Click the Procedure box arrow in the code window. Select KeyDown in the Procedures list Enter the code below, starting on line 185

41 Chapter 6: Looping and Multiple Forms 41 Coding a Form Resize Event Click the Object box arrow in the code window Click Base Class Events in the Object list. Click the Procedures box arrow in the Procedures box in the code window. Select Resize in the Procedures list Enter the below lines of code, starting on line 191

42 Chapter 6: Looping and Multiple Forms 42 The Me Keyword and Coding a Second Form Click the Add Item Form.vb[Design] tab in the main work area. Double-click the btnOK button. Enter Option Strict On as the first line of code in the form Enter lines 120 through 127 of the code on the following slide Click the Add Item Form.vb[Design] tab in the main work area. Double-click any blank area on the form. Type lines 131 through 136 of code in the frmAddItem_Load event procedure

43 Chapter 6: Looping and Multiple Forms 43

44 Chapter 6: Looping and Multiple Forms 44 Setting the Startup Object for a Project Click the Today’s Sales Check project in the Solution Explorer window and then click the Property Page button in the Properties window Click the Startupobject box arrow. Select frmTodaySalesCheck in the list

45 Chapter 6: Looping and Multiple Forms 45 Click the OK button

46 Chapter 6: Looping and Multiple Forms 46 Finish the Project Click the Save All button on the Standard toolbar Test your project with the test data on page VB 6.79 Print your program’s documentation Quit Visual Basic.NET

47 Chapter 6: Looping and Multiple Forms 47 Summary Add additional forms to a project Change the default icon on the title bar of a form Use the ListView controls to display a list of items on a form Use the CheckBox controls in an application Use the Anchor property of controls

48 Chapter 6: Looping and Multiple Forms 48 Summary Work with Collections in code Code a Do Until loop Code a Do While loop Code a For…Next and a For Each…Next loop Code a concatenation operator

49 Chapter 6: Looping and Multiple Forms 49 Summary Code a keyboard event Code a form Resize event procedure Work with multiple code windows Specify a Startup object for a project

50 Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Complete


Download ppt "Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms."

Similar presentations


Ads by Google