3 Replies - 1119 Views - Last Post: 21 March 2009 - 09:42 AM Rate Topic: -----

#1 rapwells   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-February 09

Sequential Files2

Post icon  Posted 19 March 2009 - 06:04 PM

14 errors please help...
Imports System.IO
Imports System.Convert

' The structure describing a customer.
Public Structure Customer
	Public EmployeeID As Integer
	Public Name As String
	Public Address As String
	Public SSN As String
	Public PayrollDate As Date
	Public GrossPay As Double
	Public WithholdingTax As Single
	Public FICATax As Single
	Public NetPay As Single
End Structure

' The CustomerList class contains members to read and write a customers file into a hidden array. Additional methods 
' locate a customer, and add, change and delete a customer.
Public Class CustomerList

	Private CurrentReader As StreamReader
	Private CurrentWriter As StreamWriter

	Private CurrentList(0) As Customer
	Private RecordCount As Integer

	' Read the customer file when an instance of the CustomerList class is created.
	Public Sub New(ByVal argFile As String)

		' Create the StreamReader.
		CurrentReader = New StreamReader(argFile)

		' Call the hidden procedure to read the input file.
		Call ReadCustomers(argFile)

		' Close the StreamReader.
		CurrentReader.Close()
	End Sub

	' The hidden ReadCustomers procedure is used to read the input file. The file name is passed as an argument.
	Private Sub ReadCustomers(ByVal argfile As String)
		Dim CurrentCustomer As Customer
		Dim Fields() As String
		Dim CurrentRecord As String
		Dim DelimiterChars() As Char = {ToChar(",")}

		' Perform the priming read to read the first line (record) in the file.
		CurrentRecord = CurrentReader.ReadLine()

		' Process each record until there are no more records to be processed.
		Do Until CurrentRecord Is Nothing

			' Split the current record using the delimiter character.
			Fields = CurrentRecord.Split(DelimiterChars)

			' Copy the fields to the current record performing type conversion as necessary.
			With CurrentCustomer
				.EmployeeID = Integer(Fields(0))
				.Name = Fields(1)
				.Address = Fields(2)
				.SSN = Fields(3)
				.PayrollDate = Date(4)
				.GrossPay = Single(Fields(5))
				.WithholdingTax = Single(Fields(6))
				.FICATax = Single(Fields(7))
				.NetPay = Single(Fields(8))
			End With

			' Increase the size of the list by one element.
			ReDim Preserve CurrentList(RecordCount)

			' Store the current structure in the list.
			CurrentList(RecordCount) = CurrentCustomer

			' Read the next line and increment the record counter.
			CurrentRecord = CurrentReader.ReadLine()
			RecordCount += 1
		Loop

		' Decrement the record counter because its value is overstated by one.
		RecordCount -= 1
	End Sub

	' Write the array back to a file. The file name is passed as an argument to the method.
	Public Sub WriteCustomers(ByVal argfile As String)

		' Create the StreamWriter.
		CurrentWriter = New StreamWriter(argfile)
		Dim CurrentRecord As Integer

		' The For loop writes each record.
		For CurrentRecord = 0 To RecordCount
			With CurrentList(CurrentRecord)
				CurrentWriter.Write(.EmployeeID)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.Name)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.Address)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.SSN)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.PayrollDate)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.GrossPay.ToString)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.WithholdingTax.ToString)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.FICATax.ToString)
				CurrentWriter.Write(",")
				CurrentWriter.Write(.NetPay.ToString)
				CurrentWriter.WriteLine()
			End With
		Next

		' Close the file when writing is complete.
		CurrentWriter.Close()
	End Sub

	' Get the largest index of the array. 
	Public Function GetLargestIndex() As Integer
		Return CurrentList.GetUpperBound(0)
	End Function

	' Return a Customer structure. The index of the customer is passed as an argument.
	Public Function GetCustomer(ByVal arg As Integer) As Customer
		Return CurrentList(arg)
	End Function

	' Add a new customer. The customer is passed as an argument.
	Public Sub AddCustomer(ByVal arg As Customer)

		' Increment the record counter because there is now one more record.
		RecordCount += 1

		' Increase the array size by one.
		ReDim Preserve CurrentList(RecordCount)

		' Store the customer, passed as an argument, in the 
		' array.
		CurrentList(RecordCount) = arg
	End Sub

	' Replace a customer. The index of the customer to replace and the
	' customer are passed as arguments.
	Public Sub ChangeCustomer(ByVal arg As Customer, ByVal argIndex As Integer)
		CurrentList(argIndex) = arg
	End Sub

	' Delete the current customer.
	Public Sub DeleteCustomer(ByVal argIndex As Integer)
		Dim Count As Integer

		' The loop shifts the array elements.
		For Count = argIndex To CurrentList.GetUpperBound(0) - 1
			CurrentList(Count) = CurrentList(Count + 1)
		Next

		' Decrease the array size by one.
		ReDim Preserve CurrentList(CurrentList.GetUpperBound(0) - 1)

		' Decrement the record counter.
		RecordCount -= 1
	End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Sequential Files2

#2 BetaWar   User is online

  • #include "soul.h"
  • member icon

Reputation: 1533
  • View blog
  • Posts: 8,325
  • Joined: 07-September 06

Re: Sequential Files2

Posted 19 March 2009 - 06:10 PM

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 rapwells   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-February 09

Re: Sequential Files2

Posted 19 March 2009 - 08:48 PM

Error 1 class 'Class1' and structure 'Class1' conflict in namespace

Error 2 'Private Sub ReadCustomers(argFile As String)' has multiple definitions with identical signatures.

Error 3 'Integer' is a type and cannot be used as an expression.
Error 4 '.' expected.
Error 5 'Date' is a type and cannot be used as an expression.
Error 6 '.' expected.
Error 7 'Single' is a type and cannot be used as an expression.

And this is what I am trying to do.
You will create an application that reads two sequential files. The first file contains employee information. The second file contains payroll information for each employee. The record formats are listed below.

Employee File
Employee ID - Integer
Name - String
Address - String
SSN - String

Payroll File
Employee ID - Integer
Payroll Date - Date
Gross Pay - Single
Withholding Tax - Single
FICA Tax - Single
Net Pay - Single

1. Create the two structures and module-level dynamic arrays to store the data described above.
2. Create an Open Files button. In the Click event handler, write the code to open the employee and the payroll file and store the records in an array. As you read each employee records, write the statement to add the employee ID numbers to the combo box.
3. Write the code so that when the user clicks an item in the combo box, the employee name, address, and ssn appear in the labels below the combo box.
4. Write the code to display the payroll information for the selected employee ID.
5. Write the code to calculate the totals for each list box and display the values in labels below the list boxes.
Was This Post Helpful? 0
  • +
  • -

#4 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: Sequential Files2

Posted 21 March 2009 - 09:42 AM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1