Title: List Box Control
1List 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)
2GUI 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
3AddItem 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
4Arrangement 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
5Sorted 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
6ListIndex 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
7Default 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
8Program 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
9Fields, 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
10Sequential 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
11Open 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
12Sequential 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
13Record 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
14Write 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
15Close 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
16Verifying 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
17Sequential Access File
18EOF 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)
19Input 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
20Print 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
21Print 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
22Printing 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
23Spc 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
24Fixed-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
25Right-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
26Format 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
27RSet 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
28Printer 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
29MultiLine 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
30ScrollBars 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
31Sizing 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
32Menus
- 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
33Menu Elements in User Interface
34Menu Elements in Menu Editor
35Access 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
36Shortcut Keys
- Assign to commonly used menu commands
- Displayed to the right of the menu item
- Can be used only when the menu is closed
37More 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
38Separator 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
39Clipboard Object
- Provides access to the Windows clipboard
- Allows you to include cut, copy, and paste
capabilities in your application
40Methods 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
41SelText 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)
43Edit Menu Click Event
44Copy Command Click Event
45Cut Command Click Event
46Paste Command Click Event
47String 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
48Instr 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
49Debugging 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