Results 1 to 5 of 5

Thread: Cannot run a function in a class project

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Cannot run a function in a class project

    Hi Again All,

    I am trying to use one function in a class module in another function of another class module. Both class modules are in the same class project. I keep getting an error that the Sub or Function was not defined. If I move the function into the class module I am calling it from everything works fine.

    Could some one please tell me what I am doing wrong.
    Thanks
    This space for rent...

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    The error may be because of the way you are declaring the sub or function. From the MSDN help;

    [Private | Public | Friend] [Static] Sub name [(arglist)]
    [statements]
    [Exit Sub]
    [statements]

    End Sub

    The Sub statement syntax has these parts:

    Public - Optional. Indicates that the Sub procedure is accessible to all other procedures in all modules. If used in a module that contains an Option Private statement, the procedure is not available outside the project.

    Private - Optional. Indicates that the Sub procedure is accessible only to other procedures in the module where it is declared.

    Friend - Optional. Used only in a class module. Indicates that the Sub procedure is visible throughout the project, but not visible to a controller of an instance of an object.

    Static - Optional. Indicates that the Sub procedure's local variables are preserved between calls. The Static attribute doesn't affect variables that are declared outside the Sub, even if they are used in the procedure.
    Perhaps you should be using

    Friend Sub xxxxxx

    etc
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    I have added my code below. I have the function that I am calling defined as a public function so I don't know what gives.

    Both file.cls and string.cls are in the same project.

    In File.cls
    Code:
    Public Function CreateFolder(ByVal _
                            CompleteDirectory As String) As Integer
    
        drivePart = GetPart(CompleteDirectory, "\")
    
    End Function
    In String.cls
    Code:
    Public Function GetPart(InputString As String, Delimiter As String) As String
    
    ' Takes a string separated by "delimiter", splits off 1 item, and shortens the string so that the
    ' next item is ready for removal.
    
    Dim c As Integer
    Dim Item As String
    
        c = 1
        
        Do
            If Mid$(InputString, c, 1) = Delimiter Then
                Item = Mid$(InputString, 1, c)
                InputString = Mid$(InputString, c + 1, Len(InputString))
                GetPart = Item
                Exit Function
            End If
            c = c + 1
        Loop
    
    End Function
    This space for rent...

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    you might wanna trie this:

    VB Code:
    1. Public Function CreateFolder(ByVal _
    2.                         CompleteDirectory As String) As Integer
    3.  
    4.     Dim s as new String '(object of type string.cls ... bad naming though :) )
    5.     drivePart = s.GetPart(CompleteDirectory, "\")
    6.  
    7. End Function
    -= a peet post =-

  5. #5

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Thanks
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width