UPDATING A RANDOM-ACCESS DATA FILE: BASEBALL TEAM RECORDS in VS .NET

Maker QR-Code in VS .NET UPDATING A RANDOM-ACCESS DATA FILE: BASEBALL TEAM RECORDS

EXAMPLE 9.11 UPDATING A RANDOM-ACCESS DATA FILE: BASEBALL TEAM RECORDS
Denso QR Bar Code Reader In .NET
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in .NET framework applications.
Create Quick Response Code In Visual Studio .NET
Using Barcode printer for .NET framework Control to generate, create Quick Response Code image in Visual Studio .NET applications.
A Little League manager keeps records of all teams within the league on a personal computer. The records are maintained in a random access data file. Each record contains the team name, the number of wins and the number of losses. After each round of new games, the manager updates the records by reading each record from the data file and adjusting the total number of wins and losses for each team. Each updated record is written to the data file as soon as it is adjusted. To make the adjustments, the current team status (team name, number of wins, number of losses and percentage of games won) will displayed on the screen, within labeled text boxes. This program is used to update a file called Teams.dat, containing the following information. (Presumably, the file containing this information will have been created with another Visual Basic program.)
Scanning Quick Response Code In .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET framework applications.
Barcode Generator In .NET
Using Barcode creation for VS .NET Control to generate, create barcode image in Visual Studio .NET applications.
DATA FILES
Barcode Recognizer In .NET Framework
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
QR Code 2d Barcode Drawer In Visual C#.NET
Using Barcode printer for .NET Control to generate, create QR Code 2d barcode image in Visual Studio .NET applications.
[CHAP. 9
Make QR Code 2d Barcode In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
Generating QR-Code In Visual Basic .NET
Using Barcode creation for Visual Studio .NET Control to generate, create Quick Response Code image in .NET applications.
Team Name Giants Jets Nerds Rockets Sluggers Techies
Making Matrix Barcode In VS .NET
Using Barcode generator for .NET Control to generate, create Matrix Barcode image in VS .NET applications.
Barcode Generator In Visual Studio .NET
Using Barcode maker for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
Wins 3 1 3 5 4 5
Making GS1 DataBar Stacked In .NET Framework
Using Barcode generator for Visual Studio .NET Control to generate, create GS1 DataBar Truncated image in .NET applications.
Create British Royal Mail 4-State Customer Code In Visual Studio .NET
Using Barcode generation for .NET framework Control to generate, create RoyalMail4SCC image in .NET framework applications.
Losses 4 6 4 2 3 2
Barcode Generation In Java
Using Barcode generator for Java Control to generate, create barcode image in Java applications.
Code-128 Printer In None
Using Barcode drawer for Online Control to generate, create Code 128A image in Online applications.
The preliminary control layout is shown in Fig. 9.55, and the File menu entries are shown in Fig. 9.56.
Recognizing UPC-A In Visual C#
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
Generate EAN-13 Supplement 5 In None
Using Barcode drawer for Word Control to generate, create EAN-13 image in Word applications.
Fig. 9.55
Create Code 39 Extended In Objective-C
Using Barcode creation for iPhone Control to generate, create Code 3 of 9 image in iPhone applications.
UPC Code Reader In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
The corresponding menu editor entries are shown below. Caption
Bar Code Encoder In Java
Using Barcode creator for Java Control to generate, create barcode image in Java applications.
Printing Linear Barcode In VS .NET
Using Barcode creator for ASP.NET Control to generate, create 1D image in ASP.NET applications.
File ....&Open ........&End
Fig. 9.56
Name
mnuFile mnuOpen mnuSep1 mnuEnd
We will assign values to the control properties during runtime so that the opening form appears as shown below, in Fig. 9.57.
Fig. 9.57
CHAP. 9]
DATA FILES
Here is the complete program listing.
Private Type RecordType Name As String * 8 Wins As Integer Losses As Integer End Type Private Team As RecordType Private Last As Integer, RecNo As Integer Private Sub Form_Load() Form1.Caption = "Record Updates" Label1.Caption = "Updating Little League Records" Label1.FontSize = 12 Label1.Alignment = 2 'center text Label2.Caption = "Team:" Label2.FontSize = 10 Label2.Enabled = False Label3.Caption = "Wins:" Label3.FontSize = 10 Label3.Enabled = False Label4.Caption = "Losses:" Label4.FontSize = 10 Label4.Enabled = False Text1.Text = "" Text1.FontSize = 10 Text1.Enabled = False Text2.Text = "" Text2.FontSize = 10 Text2.Enabled = False Text3.Text = "" Text3.FontSize = 10 Text3.Enabled = False Command1.Caption = "Update" Command1.FontSize = 10 Command1.Enabled = False Command2.Caption = "Next" Command2.FontSize = 10 Command2.Enabled = False End Sub Private Sub mnuOpen_Click() Dim TeamFile As String CommonDialog1.CancelError = True On Error GoTo CancelButton CommonDialog1.Filter = "Data file (*.dat) |*.dat"
(Continues on next page)
DATA FILES
[CHAP. 9
CommonDialog1.ShowOpen TeamFile = CommonDialog1.FileName Open TeamFile For Random As #1 Len = Len(Team) Last = LOF(1) / Len(Team) RecNo = 1 Get #1, RecNo, Team Text1.Text = Team.Name Text2.Text = Str(Team.Wins) Text3.Text = Str(Team.Losses) Label2.Enabled = True Label3.Enabled = True Label4.Enabled = True Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Command1.Enabled = True Command2.Enabled = True CancelButton: Exit Sub End Sub Private Sub mnuEnd_Click() Close #1 End End Sub Private Sub Command1_Click() Team.Name = Text1.Text 'update the current record Team.Wins = Val(Text2.Text) Team.Losses = Val(Text3.Text) Put #1, RecNo, Team If RecNo < Last Then 'get the next record RecNo = RecNo + 1 Get #1, RecNo, Team Text1.Text = Team.Name Text2.Text = Str(Team.Wins) Text3.Text = Str(Team.Losses) Else Label2.Enabled = False Label3.Enabled = False Label4.Enabled = False Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Command1.Enabled = False Command2.Enabled = False End If End Sub
(Continues on next page)
CHAP. 9]
DATA FILES
Private Sub Command2_Click() If RecNo < Last Then 'get the next record RecNo = RecNo + 1 Get #1, RecNo, Team Text1.Text = Team.Name Text2.Text = Str(Team.Wins) Text3.Text = Str(Team.Losses) Else Label2.Enabled = False Label3.Enabled = False Label4.Enabled = False Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Command1.Enabled = False Command2.Enabled = False End If End Sub
This program utilizes a record type consisting of the team name, the number of wins, and the number of losses. Note that the record-type variable Team, the integer variables Last and RecNo are defined as global variables so that they can be accessed in multiple event procedures. Event procedure Form_Load assigns values to various control properties and disables most of the controls until a data file has been identified and opened. This occurs in event procedure mnuOpen_Click. In addition, the first record is read from the data file and its contents displayed on the screen, and the disabled controls are enabled in mnuOpen_Click. The Get # statement is used to read from the data file. Event procedure Command1_Click corresponds to the Update button. It writes the values displayed on the screen (which are assumed to have been modified) back to the data file. The Put # statement is used to write to the data file. If additional records remain in the data file, the next record is then read and displayed on the screen. Otherwise, most of the controls are again disabled. Note that the modified record is written to the same data file from which it was read, on channel 1. Event procedure Command2_Click corresponds to the Next button. It is similar to the event procedure called Command1_Click, but it does not write the values displayed on the screen to the data file. This event procedure is used when the record currently displayed is to remain unchanged.
Copyright © OnBarcode.com . All rights reserved.