Download presentation
Presentation is loading. Please wait.
Published byVirginia Henry Modified over 9 years ago
2
What are the different types of loops? ◦ Do….While Performs statements within loop while a condition is true ◦ Do….Until Performs statements within loop until a condition is true ◦ For….Next Performs statements within the loop a pre-determined number of times Within these there are two styles ◦ Post-test Code is executed at least once ◦ Pre-test Code may not get execute.
3
Can be top controlled or bottom controlled Top Controlled syntax Do While condition Body of loop Loop Bottom Controlled syntax Do Body of loop Loop while condition
6
Much like the Do…While can be top or bottom controlled Top Controlled Do until condition Body of loop Loop Bottom Controlled Do Body of loop Loop until condition
7
You can use a For...Next loop when a section of code is to be executed an exact number of times
9
Starting a loop with a preset value in the variable(s) tested in the condition is called priming the loop
10
10 Resolving defects in code is called debugging Breakpoints allow us to stop the code where ever we want so that we can examine what is going on with our variables. While in break mode, you can examine the values in all
11
Chapter 6: Loop Structures11 A variable that contains an accumulated value such as the total of all the speeds is called an accumulator A variable that always is incremented by a constant value is called a counter ◦ How many vehicle speeds the user has entered
12
Chapter 6: Loop Structures12 A compound operator allows you to add, subtract, multiply, divide, use modulus or exponents, or concatenate strings, storing the result in the same variable
13
Chapter 6: Loop Structures 13
14
Chapter 6: Loop Structures 14
15
15 A menu bar is a strip across the top of a window that contains one or more menu names A menu is a group of commands, or items, presented in a list
16
Chapter 6: Loop Structures 16
17
Chapter 6: Loop Structures17 Work the same for buttons – double click on the menu item and the code window should pop up
18
18 Action Tag allows you to create a full standard menu bar commonly provided in Windows programs Can specify a set of actions, called smart actions, for an object as you design a form To do this place a new MenuStrip object on your form Click the Action Tag on the MenuStrip object Click Insert Standard Items on the MenuStrip Tasks menu Click File on the menu bar to view the individual menu items and their associated icons on the File menu
19
19
20
20 The InputBox function displays a dialog box, that asks the user for some type of input. The User can either click on OK or Cancel When the user enters the text the InputBox function returns this text as a string If the user clicks the Cancel button, the function returns a null string ("")
21
Chapter 6: Loop Structures21 The InputBox object can be assigned a default value
22
22
23
23 List boxes can be used to display items for a user to pick from OR receive output from a program
24
24 Click the Items property in the Properties window Click the ellipsis button in the right column of the Items property Click in the String Collection Editor window. Type in whatever values you want and click on the OK button
25
When we use a list box to display a set of values for the user to pick from, when they pick their item, we need to bring it in to the code
26
This property returns an integer with the number of entries stored in the Items property Example of use: The number of entries in the list can be assigned to an integer variable If lstEmployees.Items.Count = 0 Then MessageBox.Show("The list has no items!") End If numEmployees = lstEmployees.Items.Count
27
The Items property values can be accessed from your VB code Each item value is given a sequential index ◦ The first item has an index of 0 ◦ The second item has an index of 1, etc. Example: name = lstCustomers.Items(2) ' Access the 3rd item value
28
The SelectIndex property returns an integer with the index of the item selected by the user If no item is selected, the value is set to -1 (an invalid index value) Can use SelectIndex to determine if an item has been selected by comparing to -1 Example: If lstLocations.SelectedIndex <> -1 Then location = lstLocations.Items(lstLocations.SelectedIndex) End If
29
Instead of using the SelectedIndex property as follows: The SelectedItem property can be used to retrieve the value of a selected item as follows: If lstMonths.SelectedIndex <> -1 Then month = lstMonths.Items(lstMonths.SelectedIndex) End If If lstMonths.SelectedIndex <> -1 Then month = lstMonths.SelectedItem.ToString) End If
30
Sorted is a boolean property When set to true, values in the Items property are displayed in alphabetical order When set to false, values in the Items property are displayed in the order they were added
31
Items can be added to the end of a ListBox list in your VB code using the Add method Format is ListBox.Items.Add(Item) ListBox is the name of the control Item is a string value to add to the Items property Example: lstStudents.Items.Add("Sharon")
32
Items can be added at a specific position of a ListBox in VB code using the Insert method ListBox.Items.Insert(Index, Item) Index specifies position where Item is placed Index is zero based similar to SelectedIndex property Items that follow are “pushed” down Example inserting "Jean“ as the 3 rd item lstStudents.Items.Insert(2, "Jean")
33
ListBox.Items.RemoveAt(Index) ◦ Removes item at the specified index ListBox.Items.Remove(Item) ◦ Removes item with value specified by Item ListBox.Items.Clear() ◦ Removes all items in the Items property Examples: lstStudents.Items.RemoveAt(2)‘remove 3 rd item lstStudents.Items.Remove(“Jean”)‘remove item Jean lstStudents.Items.Clear()‘remove all items
34
34 Right-click where ever you wish to put your breakpoint, point to breakpoint on the short cut menu. To run and test the program with the breakpoint, click the Start Debugging button on the Standard toolbar To see the value of the variable hover your mouse over the variable declaration and you will see the current value.
36
36 To remove a breakpoint, right-click the statement containing the breakpoint, and then point to Breakpoint on the shortcut menu Click Delete Breakpoint on the Breakpoint submenu
37
37 After you complete your application, how do we create the executable or deploy it? Deploying a project means placing an executable version of the program on your hard disk, on a Web server, or on a network server You can create a deployed program by using ClickOnce Deployment The deployed version of the program you create can be installed and executed on any computer that has the.NET framework installed
38
38 With the program open, click Build on the menu bar Click Publish Radar on the Build menu Change the default location from publish\ to a file location. Click the Next button. If necessary, click the From a CD-ROM or DVDROM radio button Click the Next button. If necessary, click the The application will not check for updates radio button Click on next and then finish
39
Chapter 6: Loop Structures39 To install the application, double-click the setup file After installation, the program will run. To run the installed application again, click the Start button on the Windows taskbar. Point to All Programs, click Radar on the All Programs menu, and then click Radar on the Radar submenu
40
40
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.