Hi
im trying to create a VB program that allows storing and reading to a TXT file i keep getting error 424 object required, im not all to good with VB but i have to get this working for an assignment by thursday. i can (without the loop) read and write a single persons information but i have to save many records .
im trying to create a VB program that allows storing and reading to a TXT file i keep getting error 424 object required, im not all to good with VB but i have to get this working for an assignment by thursday. i can (without the loop) read and write a single persons information but i have to save many records .
Code:
Dim Employee As Object
Dim EmployeeCollection As New Collection
Dim counter As Integer
Private Sub cmdExit_Click(Index As Integer)
Dim i As Integer
Dim counter As Integer
counter = EmployeeCollection.Count
Open "c:\temp\Storage.txt" For Output As #1
For i = 1 To counter
Write #1, EmployeeCollection.Item(i).Fullname
Print #1, EmployeeCollection.Item(i).Area
Print #1, EmployeeCollection.Item(i).Postcode
Print #1, EmployeeCollection.Item(i).Address
Print #1, EmployeeCollection.Item(i).Contactno
Print #1, EmployeeCollection.Item(i).Pos
Print #1, EmployeeCollection.Item(i).Salary
Next
Close #1
End
End Sub
Private Sub cmdNew_Click(Index As Integer)
Set Employee = New clsEmployee
Employee.Fullname = txtFullname.Text
Employee.Address = txtAddress.Text
Employee.Area = txtArea.Text
Employee.Postcode = txtPostcode.Text
Employee.Contactno = txtContactno.Text
Employee.Pos = txtPos.Text
Employee.Salary = txtSalary.Text
EmployeeCollection.Add clsEmployee
txtEmployeeno.Text = EmployeeCollection.Count
Set Employee = Nothing
txtFullname.Text = " "
txtAddress.Text = " "
txtArea.Text = " "
txtPostcode.Text = " "
txtContactno.Text = " "
txtPos.Text = " "
txtSalary = " "
End Sub
Private Sub Form_Load()
Dim FileFullname As String
Dim FileArea As String
Dim FileAddress As String
Dim FilePostcode As String
Dim FileContactno As String
Dim FilePos As String
Dim FileSalary As String
Set EmployeeCollection = New Collection
Set Employee = New clsEmployee
Open "c:\temp\Storage.txt" For Input As #1
While EOF(1) = False
Input #1, FileFullname
Input #1, FileAddress
Input #1, FileArea
Input #1, FilePostcode
Input #1, FileContactno
Input #1, FilePos
Input #1, FileSalary
Employee.Fullname = FileFullname
Employee.Address = FileAddress
Employee.Area = FileArea
Employee.Postcode = FilePostcode
Employee.Contactno = FileContactno
Employee.Pos = FilePos
Employee.Salary = FileSalary
EmployeeCollection.Add Employee
Wend
Close #1
txtEmployeeno.Text = EmployeeCollection.Count
txtFullname.Text = EmployeeCollection.Item(EmployeeCollection.Count).Fullname
txtAddress.Text = EmployeeCollection.Item(EmployeeCollection.Count).Address
txtArea.Text = EmployeeCollection.Item(EmployeeCollection.Count).Area
txtPostcode.Text = EmployeeCollection.Item(EmployeeCollection.Count).Postcode
txtContactno.Text = EmployeeCollection.Item(EmployeeCollection.Count).Contactno
txtPos.Text = EmployeeCollection.Item(EmployeeCollection.Count).Pos
txtSalary.Text = EmployeeCollection.Item(EmployeeCollection.Count).Salary
End Sub
Comment