object problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yamasassy
    New Member
    • Mar 2008
    • 15

    object problem

    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 .

    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
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    First start with narrowing it down. Which line is the Error 424 occuring on? This will help if you can step through the code during run time and try to determine where its happening.

    I also notice you are delclaring a class in your code
    Set Employee = New clsEmployee

    I assume you have a .cls file that declares the Employee properties?

    If so you need to make sure that class is referenced in your references of the project. Also make sure if they are seperate that you have compiled them in the right order. That would be my first guess of the problem.

    Comment

    • Yamasassy
      New Member
      • Mar 2008
      • 15

      #3
      Originally posted by jeffstl
      First start with narrowing it down. Which line is the Error 424 occuring on? This will help if you can step through the code during run time and try to determine where its happening.

      I also notice you are delclaring a class in your code
      Set Employee = New clsEmployee

      I assume you have a .cls file that declares the Employee properties?

      If so you need to make sure that class is referenced in your references of the project. Also make sure if they are seperate that you have compiled them in the right order. That would be my first guess of the problem.

      the problem is
      Print #1, EmployeeCollect ion.Item(i).Ful lname
      and i got clsEmployee as the main class and
      Fullname
      Address
      Area
      Postcode
      Contactno
      Pos
      and Salary as propities
      my collection is Employee

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Try defining a new object of type clsEmployee (or whatever it was, I forget). Assign each item from the collection to that object, and print from there, instead of from the collection.

        Comment

        Working...