Embed
Email

Tutorial 6

Document Sample

Categories
Tags
Stats
views:
0
posted:
11/3/2011
language:
English
pages:
4
LECTURE NOTES





Sequential Access Data Files and Reports

The list box can be used to display a set of choices from which the user can select only one item. (Note that you

can also create a multi-selection list box from which the user can make 0 or more selections.) If a list box contains

more selections than can be displayed VB adds scroll bars. A list box provides a space-saving alternative to a

series of option buttons or check boxes. For user convenience you should limit a list box to no fewer than three and

no more than eight choices. Use label control to provide keyboard access to the choices.



See Figure 6-12.



Use the AddItem method to add an item to a list box. The syntax is

control.Additem item

where item is the expression – numeric or string - you want displayed in the control. You should arrange items

either by use (most frequently used first) or sorted (alphabetically, numerically, or chronologically). You can use

the Sorted property to have VB arrange items in sorted order (true) or added to the end of the list (false). Use the

ListIndex property to refer to a list item. Note that the first item has index 0. You can (and should) identify a

default list item (either the most frequently used item or the first item).



A data file is a collection of information and is composed of fields and records. A field, also called a data element,

is a single item of information, e.g., a person’s name, age, etc. A record is a group of related fields that contain all

the necessary information about a specific person, place, or thing. A data file is a collection of related records.



A sequential access data file is similar to a cassette tape in that each record in the file, like each song on a cassette,

is both stored and retrieved in sequential order. Access time is related to position in the file. Sequential files are

easy to create, but their drawback is that records must be processed in storage order. They are most suited to

processing a small file, a text file, or a file that will only be accessed sequentially.



Sequential files are opened using the Open statement, as in

Open pathname For mode As # filenumber

Where

pathname is the filename, including its drive and path, and should be enclosed in quotes (unless it is stored

in a string variable).



Mode can either be Input, Output, or Append. For Input files, VB will open the file or issue an error if the

file does not exist. For Output, VB will open a new file or erase the contents of an existing file with the

same name. For Append, VB will open the file and allow you to add records to the end. An error message

will be issued if the file does not exist.



Filenumber is an integer between 1 and 511 that will be associated with the file as long as it is still open.



VB uses a record pointer to keep track of the next record. For an Input file, the pointer is initially positioned before

the first record. For Output, the pointer is positioned at the beginning of the file. For Append, the pointer is

positioned immediately after the last record.



You can write to a sequential access file, as in

Write # filenumber, [outputlist]

Where

Filenumber is the file number from the Open statement

outputlist is one or more numeric or string expressions, separated by commas



Close a sequential file using the syntax

Close # filenumber



When reading from a file, you can use the EOF(filenumber) function, which returns true after the last record has

been input. It is typically used in the context of a While loop, as in

Do While Not EOF(1)

Or Do Until EOF(1)



(assuming the file number is 1)



You can read from a sequential file using the following syntax:

Input #filenumber, variableist

Where

Filenumber is the file number from the Open statement

Variablelist is a list of one or more string or numeric variables, separated by commas. The variablelist

should correspond in number and data type with the data stored in each record of the file.



The Print method can be used to output data on a form. You can print to a printer using the syntax:

Printer.Print[outputlist]

Where outputlist is a list of expressions to be output. The expressions can be separated by commas or semicolons.

A comma forces the output to the next tab position, while a semicolon advances to the next print position. VB

prints positive numbers with a leading and a trailing space. Negative numbers print with a leading minus sign and a

trailing space. The Spc and Tab functions can help space the output (note: use the semicolon, not the comma with

these functions). Use the Format and RSet statements to right-justify and align numbers by the decimal point.



Explain how to uses a printer spacing chart to plan the report layout. Be sure to include a report title and column

headings. Within the chart, use 9’s to denote numbers (one 9 per digit) and X’s for characters in a string. Sub and

grand totals should be displayed as appropriate. Finally, you should tell the students to output “End of Report” to

indicate that the report has printed in its entirety.



See Figure 6-41.





QUICK QUIZ



1. What is a sequential file? ANSWER: A sequential access data file is similar to a cassette tape in that each

record in the file, like each song on a cassette, is both stored and retrieved in sequential order

2. How do you read from a file? ANSWER: use the EOF(filenumber) function, which returns true after the

last record has been input. It is typically used in the context of a While loop, as in

Do While Not EOF(1)

Or Do Until EOF(1)

3. What is a printer spacing chart? ANSWER: A paper layout showing the expected titles, column headings,

and outputs.





Menus

This lesson explains how to design and insert menus. The lesson starts by explaining the MultiLine and ScrollBars

properties. The MultiLine property controls how many lines can appear in a text box. When set to true, the text

box can accept and display more than one line. The ScrollBars property specifies whether the text box has no scroll

bars (the default), horizontal scroll bars, vertical scroll bars, or both. Note that MultiLine must be true for the scroll

bars to appear.



Controls can be sized using the ScaleHeight and ScaleWidth properties. You can enter the sizing code in the

form’s Resize event, which occurs when the form is first displayed and when the user changes the size of the form.



Use the Menu Editor to create a menu. Menus can contain titles, items, separator bars, submenu titles, and

submenu items. Try to keep to single-level menus; multi-level menus can be confusing. Each menu title and each

menu item should have a unique access key; menu titles are accessed via “Alt-Access key”. Menu items are

accessed via the access key, when the menu is open. Commonly used menu items should have a shortcut key

(allows access without opening the menu). Page 471 lists the GUI guidelines for menu design. Note that each

menu title and each menu item is considered a separate control; each has a unique Caption and Name; each can

have its own code. Menu controls can only recognize a click event.

The Clipboard object provides access to the Windows clipboard; it allows you to include cut, copy, and paste

capabilities into an application. Use the Clipboard objects SetText() method to send text to the clipboard. Use the

Clipboard object’s GetText() method to retrieve text from the Clipboard. Use the Clear() method to clear the

contents. Review each of the coding examples for coding the Edit Menu.







QUICK QUIZ

1) What is the MultiLine property? ANSWER: The MultiLine property controls how many lines can appear

in a text box.

2) What can be found in a menu? ANSWER: Menus can contain titles, items, separator bars, submenu titles,

and submenu items.

3) What is the Clipboard object? ANSWER: The Clipboard object provides access to the Windows

clipboard; it allows you to include cut, copy, and paste capabilities into an application.









String Manipulation

This lesson explains some basic string manipulation functions. The Left(string, length) function returns the

leftmost length number of characters in a string. The Right(string, length) function returns the rightmost length

number of characters in a string. The Mid(string, start[, length]) function returns length number of characters

starting from position start



The Instr(start, string1, string2[,compare]) function searches string1, starting at position start, for string2. If

compare is set to 1, the search is case-insensitive (0 is the default for case-sensitive searches). The Instr() function

returns the position in string1 where string2 begins, or 0 if string2 is not found in string1.







QUICK QUIZ



1. What is the Left() function? ANSWER: The Left(string, length) function returns the leftmost length number of

characters in a string

2. What is the Mid() function? ANSWER: The Mid(string, start[, length]) function returns length number of

characters starting from position start

3. What is the Instr() function? ANSWER: The Instr(start, string1, string2[,compare]) function returns the position

in string1, starting from position start, where string2 begins, or 0 if string2 is not found in string1.









DISCUSSION TOPICS

 What are the advantages and disadvantages of sequential data files?

 What are the advantages and disadvantages of using a printer spacing chart?

 What are the GUI guidelines for menu design?

 What are some useful examples of string processing?

EXTRA PROJECTS



1) Grader (Version 1)

Write an application that will compute a final grade for each student in a class. The data for the students should be

entered into a file called “grades.dat” and should contain grades for at least 5 students. Assume each student has

six grades with equal weighting toward the final grade for the semester:

a) homework

b) program 1

c) program 2

d) program 3

e) midterm

f) final



That is, a student receiving the following grades: 90 75 80 95 87 93 would receive a final semester grade of: 86.7



As you input each set of grades, calculate and output the final numeric grade.





2) Grader (Version 2)

Embellish Grader Version 1 as follows: Modify the application so that it will compute both a final grade and a letter

grade for each student in the class. Use the same data file as for Grader Version 1. Assume each student has six

grades, each of which carries a different weighting toward the final grade for the semester:

a) homework 10%

b) program 1 15%

c) program 2 15%

d) program 3 15%

e) midterm 20%

f) final 25%



That is, a student receiving the following grades: 90 75 80 95 87 93 would receive a final semester grade of: 87.15.

This number should then be converted to a letter grade as follows:

Number grade Letter grade

90-100 A

80-89 B

70-79 C

60-69 D

0-59 F



As you input each set of grades, calculate the final numeric grade and the corresponding letter grade. Output both

and then process the next student. Once all students have been processed, output the average, lowest, and highest

grades in the class.









KEY TERMS

.

 Clipboard Object - The Clipboard object provides access to the Windows clipboard.

 Data File– A data file is a collection of information and is composed of fields and records.

 File Access Mode – File Access Mode can either be Input, Output, or Append.

 Sequential Access File – A sequential access file must be accessed in sequential order.

 String Manipulation Functions – String manipulation functions are a set of tools for processing string

data. They allow you to pull out specific substrings or search for the presence of a substring.



Related docs
Other docs by Stariya Js @ B...
Info pack - Level 1
Views: 0  |  Downloads: 0
f1098746053
Views: 0  |  Downloads: 0
file_116
Views: 3  |  Downloads: 0
Trade
Views: 0  |  Downloads: 0
McKenzie_Law.April
Views: 0  |  Downloads: 0
110208attachmentEndingtheUseofCoalCampaign
Views: 0  |  Downloads: 0
Titration Curve _CBL_ _AP_
Views: 0  |  Downloads: 0
FSSC cover note
Views: 0  |  Downloads: 0
link_130115
Views: 0  |  Downloads: 0
Index_of_Supplementary_Tables_and_Dataset
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!