none
not recognize a member of a library class RRS feed

  • Question

  • I have a public shared function, File1, that is in a library class, Library1. This function receives a file as a parameter and return a List of Employee. It is called from the Sub Main. In the  Sub Main, I put the following codes. Assume I already have a function File1, an Employee class in the Library1 and Imports statements: Imports Library1; Imports System.IO.StreamReader; Imports System.Collections.Generic

    Dim e as new List(of Employee)
    e = Employee.File1(File.OpenRead("employees.txt"))   

                                                                            I got an error message saying that "File1 is not a member of Library1".  I suspect I wrote something wrong in the line of codes above, but as a beginner, I don't know what it is. Can you please help? Thanks.


    • Edited by Paul IshakModerator Wednesday, February 20, 2013 4:57 PM Please use codeblocks when providing code.
    Wednesday, February 20, 2013 2:27 PM

Answers

  • Hi,

    I am not sure how you are calling the File1() method. Please check the below code

    Imports Library1
    Imports System.IO
    Module Module1
    
        Sub Main()
            Dim myObj As List(Of Library1.Employee)
    
            myObj = Library1.Employee.File1(File.OpenRead("employees.txt"))
    
    
        End Sub
    
    End Module

    The above code is working fine for my sample application.

    Best Regards

    Muthuraja

    • Marked as answer by ttim Thursday, February 21, 2013 1:42 PM
    Thursday, February 21, 2013 3:33 AM

All replies

  • Hi,

    Can you share the code for File1() method. Did you mentioned the function visibility as "Public"

    Best Regards

    Muthuraja

    Wednesday, February 20, 2013 3:16 PM
  • I have a public shared function, File1, that is in a library class, Library1. This function receives a file as a parameter and return a List of Employee. It is called from the Sub Main. In the  Sub Main, I put the following codes. Assume I already have a function File1, an Employee class in the Library1 and Imports statements: Imports Library1; Imports System.IO.StreamReader; Imports System.Collections.Generic

    Dim e as new List(of Employee)
    e = Employee.File1(File.OpenRead("employees.txt"))                                                                          I got an error message saying that "File1 is not a member of Library1".  I suspect I wrote something wrong in the line of codes above, but as a beginner, I don't know what it is. Can you please help? Thanks.


    Why don't you make a reply to your original post. At the top of the reply will be a bar with various functions on it. To the right of HTML is the Insert Code Block function. Use it to add your code to in order to display your code in your reply. Then post your reply where everybody can see your code. In this way peeps may be able to assist you better.

    You've taught me everything I know but not everything you know.

    Wednesday, February 20, 2013 3:16 PM
  • Public shared function File1(ByVal test as fileStream) as List(Of Employee)
    Dim l1 = New List(Of Employee)
    Dim sr As StreamReader
    'Open file for reading
    sr=New StreamReader(test)
    While (Not rs.EndOfStream)
       Dim emp as Employee
       emp = (sr.ReadLine()) 'assume this line of code goes through
       l1.Add(emp)
    End While
    return l1
    End Function
     

    Wednesday, February 20, 2013 4:34 PM
  • Public shared function File1(ByVal test as fileStream) as List(Of Employee)
    Dim l1 = New List(Of Employee)
    Dim sr As StreamReader
    'Open file for reading
    sr=New StreamReader(test)
    While (Not rs.EndOfStream)
       Dim emp as Employee
       emp = (sr.ReadLine()) 'assume this line of code goes through
       l1.Add(emp)
    End While
    return l1
    End Function
     

    Please show how the containing class is declared too.

    ex:

    Public Class MyClass1
        'Whatever stuff
    End Class
    
    Private Class MyClass2
        'Whatever stuff
    End Class


    “If you want something you've never had, you need to do something you've never done.”

    Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

    Wednesday, February 20, 2013 5:01 PM
    Moderator
  • Hi,

    You code has compiler error.

    Add two class in Library1. Class1.vb and Employee.VB

    Code inside the Class1.vb

    Imports System.IO
    
    Public Class Class1
        Public Shared Function File1(ByVal test As fileStream) As List(Of Employee)
            Dim l1 = New List(Of Employee)
            Dim sr As StreamReader
            'Open file for reading
            sr = New StreamReader(test)
            While (Not sr.EndOfStream)
                Dim emp As Employee
    'process the data from stream and store it into the Employee object
                'emp = sr.ReadLine() assume this line of code goes through
                l1.Add(emp)
            End While
            Return l1
        End Function
    End Class

    Define the members in Employee.vb and compile the project.

    Now, I created the Console application and referenced the Library1.dll.

    I can access the File1() method in console application and below is the code

    Imports Library1
    Imports System.IO
    Module Module1
    
        Sub Main()
            Dim myObj As List(Of Library1.Employee)
    
            myObj = Library1.Class1.File1(File.OpenRead("employees.txt"))
    
    
        End Sub
    
    End Module

    Let me know if you have any clarification.

    Best Regards

    Muthuraja


    Wednesday, February 20, 2013 5:05 PM
  • Thanks Muthuraja. I defined members (function File1) in Employee.vb and compile the library successfully, but it still doesn't recognize File1.  
    Wednesday, February 20, 2013 7:54 PM
  • Hi,

    I am not sure how you are calling the File1() method. Please check the below code

    Imports Library1
    Imports System.IO
    Module Module1
    
        Sub Main()
            Dim myObj As List(Of Library1.Employee)
    
            myObj = Library1.Employee.File1(File.OpenRead("employees.txt"))
    
    
        End Sub
    
    End Module

    The above code is working fine for my sample application.

    Best Regards

    Muthuraja

    • Marked as answer by ttim Thursday, February 21, 2013 1:42 PM
    Thursday, February 21, 2013 3:33 AM
  • Hi Muthuraja, it's my fault. The reference was wrong and I just fixed it and it's OK now. Thanks again.
    Thursday, February 21, 2013 1:42 PM