1 / 13

Lists and Loops List boxes and combo boxes List box - list of items

Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items - different styles - dropdown - simple combo - dropdown style - useful for a list which the user is allowed to modify

kinnear
Download Presentation

Lists and Loops List boxes and combo boxes List box - list of items

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items - different styles - dropdown - simple combo - dropdown style - useful for a list which the user is allowed to modify There is no Caption for most of these. The Name appears at design-time, but not at run-time.

  2. Filling the list at design time Fig. 7.3, 7.4 - in the Properties window, select List - enter items and <ctrl> <return> - hit <return> to exit Filling the list at run time - use the AddItem method Example lstDrinks.AddItem “Tea” cboFood.AddItem txtMessage.Text Example P. 203 The Listindex property - each item in a list has an index; indexes start at 0 - when an item is highlighted, then Listindex is set to that value

  3. Example Consider the list Drinks List Index Coffee 0 Tea 1 Milk 2 When the user highlights “Tea”, the Listindex is set to 1. To deselect all items, set Listindex to -1. Example lstDrinks.ListIndex = -1 Example P. 203 The Listcount property Listcount is the number of elements in a list Example lblMessage.Caption = lstDrinks.ListCount will print “3” on the form.

  4. Note:ListCount equals (highest index in the list) + 1 The List Property Display an element of a list Example To put “Milk” on the form lstDrinks.ListIndex = 2 lblMessage.Caption = lstDrinks.List (lstDrinks.ListIndex) Change an element of a list Example To replace “Tea” with ‘Coke” lstDrinks.List(1) = “Coke” Example P. 204

  5. 1. Create a form with a list box and with each of the three different styles of combo boxes. 2. Enter a list for each box. 3. Write command buttons to do the following to one of the lists: - add an item - display an item - change an item

  6. For/Next Loops Definition A loop is a set of instructions which is executed more than once. Example P. 204 Dim iLoopIndex As Integer For iLoopIndex = 1 to lstSchools.ListCount do something Next iLoopIndex Suppose that ListCount is 3. condition iLoopIndex is 1 actions do something increment iLoopIndex condition iLoopIndex is 2 actionsdo something increment iLoopIndex condition iLoopIndex is 3 actionsdo something increment iLoopIndex condition iLoopIndex is 3 actions go to the first isntruction after the loop

  7. Initialize iLoopCounter iLoopCounter < = ListCount False True do something Exit the loop (execute the first instruction after the Next statement) increment iLoopCounter Example Note that the example in the book has a Null False branch. The flowchart should be drawn as shown here.

  8. Dim iLoopIndex As Integer For iLoopIndex = 1 to lstSchools.ListCount do something Next iLoopIndex Definition The variable iLoopIndex is called the loop control variable, or counter. The number 1 is the lower bound or initial value of the loop control variable. The variable lstSchool.Count holds the upper bound or terminal value of the loop control variable. Important Do NOT attempt to change the value of the counter or the bounds within the loop. You may print them only.

  9. Altering the values of the loop control variable NO!!!

  10. Exiting For/Next loops NO!!!

  11. Negative increment on counting loops Example For iCount = 10 to 1 Step -1 Next iCount Infinite loops It is possible that you write a loop which does not terminate. Example For iCount = 10 to 1 Next iCount In this case, stop the execution of the program, start the program again, and Step through the code. Note: If your program runs but nothing happens, it may be in an infinite loop.

  12. Modify the last lab assignment. Write a loop to print out all the elements of one of your lists. Put each element into a separate label. Use a loop control array for the labels. Sending information to the printer (for creating reports) The command is Printer.Print Formatting lines - commas advance output one “print area” - semicolons separate items without as much space - trailing commas and semicolons print on the same line - print a blank line Printer.Print “ “ - the Tab function - specify the position where you want output - TAB (position)

  13. - the Spc function - skip a number of spaces - Spc (value) Selecting the font Example Printer.Font.Name = “Times” Printer.Font.Size = 24 Terminating the page Printer.NewPage Terminating the job Printer.EndDoc

More Related