List Box Control - PowerPoint PPT Presentation

1 / 49
About This Presentation
Title:

List Box Control

Description:

List Box Control ... If set the True, the list box items will be sorted in ascending order ... Controls how many lines a text box can both accept and display ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 50
Provided by: Dian71
Category:
Tags: box | control | list

less

Transcript and Presenter's Notes

Title: List Box Control


1
List Box Control
  • Can be used to display a set of choices from
    which the user can select only one
  • You also can create multi-selection list boxes
    from which the user can select zero or more
    choices (See Lesson As Discovery Exercise 11)

2
GUI Standards for List Boxes
  • List boxes should contain a minimum of three
    selections
  • You should display a minimum of three selections
    and a maximum of eight selections at a time
  • Use a label control to provide keyboard access to
    the list box

3
AddItem Method
  • Used to add items to a list box
  • Syntax
  • control.AddItem item
  • item is the expression you want displayed, and it
    can be either numeric or string
  • if item is a literal string constant, then it
    must be enclosed in quotation marks

4
Arrangement of List Box Items
  • By use, with the most used entries appearing
    first in the list
  • Sorted in ascending order either alphabetically,
    numerically, or chronologically

5
Sorted Property
  • Can be set to either the Boolean value True or
    the Boolean value False
  • If set the True, the list box items will be
    sorted in ascending order
  • If set to False, the list box items will appear
    in the order in which they were entered

6
ListIndex Property
  • You can use the ListIndex property to refer to an
    item in the list box
  • The first item in a list box has a ListIndex
    value of 0
  • If no items are selected in the list box, the
    ListIndex property has a value of -1

7
Default Item
  • It is customary to select a default item in a
    single-selection list box when the interface
    first appears
  • The default item should be either the most used
    selection or the first selection in the list
  • lstName.ListIndex 0 will select the first item
    in the lstName list box
  • A default selection typically is not made in a
    multi-selection list box

8
Program Files vs Data Files
  • A program file contains the instructions that
    both create the user interface and tell the
    objects how to respond to events
  • A data file is a collection of information
    composed of fields and records

9
Fields, Records, and Data Files
  • A field is a single item of information about a
    person, place, or thing
  • A record is a group of related fields that
    contain all of the necessary data about a
    specific person, place, or thing
  • A data file is a collection of related records

10
Sequential Access Data Files
  • Similar to a cassette tape in that each record in
    the file is both stored and retrieved in
    consecutive order
  • Advantage easy to create
  • Disadvantage you can process the records only in
    the order in which they were entered
  • Use for small files, files consisting only of
    text, or files that will always be accessed in
    sequential order

11
Open Statement
  • Open pathname For mode As filenumber
  • pathname is the name of the file you want to
    open it should include the drive letter and
    path, and it must be enclosed in quotation marks
    (unless it is stored in a String variable
  • mode can be either Input, Output, or Append
  • filenumber is a number that you assign to the
    file, and it must be an integer between 1 and
    511, inclusive

12
Sequential Access File Modes
  • Input - you open a file for Input when you want
    to read the file
  • Output - you open a file for Output when you want
    to create a new file and then write data to it
  • Append - you open a file for Append when you want
    to add data to the end of an existing file

13
Record Pointer
  • When you open a file for Input, the record
    pointer is positioned at the beginning of the
    file, immediately before the first record
  • When you open a file for Output, the record
    pointer is positioned at the beginning of the
    empty file
  • When you open a file for Append, the record
    pointer is positioned immediately after the last
    record in the file

14
Write Statement
  • Write filenumber, outputlist
  • filenumber is the number used in the Open
    statement to open the file
  • outputlist is one or more numeric or string
    expressions, separated by commas

15
Close Statement
  • Close filenumber
  • filenumber is the number used in the Open
    statement to open the file
  • A Close statement with no filenumber closes all
    open files

16
Verifying the Contents of a Sequential Access File
  • Use a basic word processor or text editor
  • Each line in the sequential access file
    represents a record
  • Fields in the record are separated by commas
  • String fields are enclosed in quotation marks

17
Sequential Access File
18
EOF Function
  • EOF(filenumber)
  • filenumber is the number used in the Open
    statement to open the file
  • EOF stands for end of file
  • returns the Boolean value True if the record
    pointer is at the end of the file (after the last
    record) otherwise it returns the Boolean value
    False
  • Do While Not EOF(1)
  • Do Until EOF(1)

19
Input Statement
  • Input filenumber, variablelist
  • filenumber is the number used in the Open
    statement to open the file
  • variablelist is one or more numeric or string
    variables, separated by commas
  • Each variable in the variablelist is associated
    with a field in the record
  • The number, data type, and order of the variables
    in the variablelist must match the fields in the
    record

20
Print Method
  • Print outputlist - prints to the form
  • Printer.Print outputlist prints to the printer
  • Printer is a keyword that refers to the Printer
    object
  • Outputlist is the expression or list of
    expressions you want to print if outputlist is
    omitted, the Print method prints a blank line

21
Print Method Separators
  • Comma - tells Visual Basic to tab to the next
    print zone before printing the next character
  • Semicolon - tells Visual Basic to move to the
    next print position before printing the next
    character
  • You also can use the spacebar in place of the
    semicolon

22
Printing Strings and Numbers
  • When you print a string literal constant, Visual
    Basic prints only the characters included within
    the quotation marks
  • Visual Basic prints positive numbers with both a
    leading and a trailing space
  • Visual Basic prints negative numbers with a
    leading minus sign and a trailing space

23
Spc and Tab Functions
  • Spc(number)
  • Number represents the number of spaces to insert
    before displaying or printing the next item in
    the outputlist
  • Tab(number)
  • Number represents the column number, or print
    position, to which you want Visual Basic to tab
    before printing the next item in the outputlist

24
Fixed-spaced vs Proportionally-spaced Fonts
  • Fixed-spaced fonts
  • Also called monospaced fonts
  • Use the same amount of space to print each
    character
  • Courier New is a fixed-spaced font
  • Proportionally-spaced fonts
  • Use varying amounts of space to print characters
  • MS Sans Serif is a proportionally-spaced font

25
Right-justifying and Aligning Numbers by Decimal
Point
  • Use the Format function to ensure that each
    number in the column has the same number of
    digits to the right of the decimal point
  • Use the RSet statement to right-align the numbers
    within the column

26
Format Function
  • Format(expression, format)
  • expression specifies the number, date, time, or
    string whose appearance you want to format
  • format is either the name of a predefined Visual
    Basic format or a string containing special
    symbols that tell Visual Basic how you want the
    expression displayed

27
RSet Statement
  • RSet stringvariable string
  • stringvariable is the name of a fixed-length
    String variable
  • A fixed-length String variable is one whose
    maximum length is defined when the variable is
    created
  • Dim variablename As String number
  • string is the expression you want right-aligned

28
Printer Spacing Chart
  • Reports should have a report title and column
    headings
  • Detail lines show the information used to
    calculate the subtotals and grand total
  • 999 indicates numbers having a maximum of 3
    digits
  • XXX indicates a string having a maximum of 3
    characters
  • Include an End of report message

29
MultiLine Property
  • Controls how many lines a text box can both
    accept and display
  • Can be set to either True or False (default)
  • Visual Basic automatically wraps the text in a
    multiline box if the text extends beyond the size
    of the box

30
ScrollBars Property
  • Specifies whether a text box has no scroll bars,
    horizontal scroll bars, vertical scroll bars, or
    both horizontal and vertical scroll bars
  • Visual Basic ignores the value in the ScrollBars
    property unless the MultiLine property is set to
    True

31
Sizing a Control Along with the Form
  • Set the controls Height and Width properties to
    the forms ScaleHeight and ScaleWidth properties
  • Enter the sizing code in the forms Resize event,
    which occurs when the form is first displayed on
    the screen and when the user changes the size of
    the form either by minimizing, maximizing, or
    restoring it, or by using the forms borders to
    resize it

32
Menus
  • Created in the Menu Editor
  • Can contain menu titles, menu items, separator
    bars, submenu titles, and submenu items
  • To avoid confusion, it is best to use one level
    of menus

33
Menu Elements in User Interface
34
Menu Elements in Menu Editor
35
Access Keys
  • Assign to each menu title and each menu item
  • Must be unique within a menu
  • Menu titles are accessed by pressing the Alt key
    and the access key
  • Menu items are accessed by pressing the access
    key when the menu is open

36
Shortcut Keys
  • Assign to commonly used menu commands
  • Displayed to the right of the menu item
  • Can be used only when the menu is closed

37
More on Menu Controls
  • You must provide a name and a caption for each
    menu control
  • Each menu title and each menu item is considered
    a separate control and it can have its own code
  • A menu control can recognize only the Click event

38
Separator Bar
  • A separator bar is a horizontal line used to
    separate two groups of menu items
  • Created by entering a hyphen in the menu
    controls Caption property
  • Even separator bars must have a name

39
Clipboard Object
  • Provides access to the Windows clipboard
  • Allows you to include cut, copy, and paste
    capabilities in your application

40
Methods of the Clipboard Object
  • SetText method
  • sends text to the clipboard
  • Clipboard.SetText data
  • GetText() method
  • retrieves text from the clipboard
  • Clipboard.GetText()
  • Clear method
  • clears the contents of the clipboard
  • object.Clear

41
SelText Property
  • When a user selects text in a text box, Visual
    Basic records the text in the text boxs SelText
    property
  • This property contains a zero-length string if no
    text is selected
  • You also can use the SelLength property to
    determine if any text is selected in the text box

42
(No Transcript)
43
Edit Menu Click Event
44
Copy Command Click Event
45
Cut Command Click Event
46
Paste Command Click Event
47
String Manipulation Functions
  • Left(string, length)
  • returns the leftmost length characters in the
    string
  • Right(string, length)
  • returns the rightmost length characters in the
    string
  • Mid(string, start, length)
  • returns length characters from string, beginning
    with start

48
Instr Function
  • Instr(start, string1, string2,compare
  • start is a numeric expression that sets the
    starting position for the search
  • string1 is the string expression being searched
  • string2 is the string expression being sought
  • compare is either 0 (default case-sensitive) or
    1 (case-insensitive)
  • returns the starting position of string2 within
    string1

49
Debugging Technique
  • Visual Basics Edit menu provides two commands
    that you can use to edit the code in an
    application quickly. These commands are Find and
    Replace
Write a Comment
User Comments (0)
About PowerShow.com