Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:43:31+00:00 2026-06-14T09:43:31+00:00

I am new to QTP, just started using it. I have written one class

  • 0

I am new to QTP, just started using it. I have written one class definition in some functional library and also created a test as under:

Class ExcelFileReader
Public default Function Init(pathToExcel)
   Dim objFSO
   Dim result
   Set objFSO = CreateObject("Scripting.FileSystemObject")

   If objFSO.FileExists(pathToExcel) Then
            Rem File Found
            Dim objExcel
            Set objExcel = CreateObject("Excel.Application")
            objExcel.Workbooks.open(pathToExcel)

       Else
            REM File not found
            result = vbOk
            While result <> vbCancel
                result = Msgbox ("Unable to Locate the file", 5, "Error")
            Wend
            ExitAction(1)
       End If
End Function

End Class

Test:

 Dim objExcelReader : Set objExcelReader = New ExcelFileReader
objExcelReader.Init("D:\mytest.xlsx")

I have associated the functional library with the test but still I am getting an error at line number 2 in test stating class definition not found. Also if I copy complete code in the same file “test” then the things are working as intended.

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:43:33+00:00Added an answer on June 14, 2026 at 9:43 am

    Classes have local scope in your library. You have to construct them with a public function to make them publicly available:

    Public Function new_ExcelFileReader()
        Set new_ExcelFileReader = new ExcelFileReader
    End Function
    
    Class ExcelFileReader
        Sub Class_Initialize
            MsgBox "Present!"
        End Sub
    End Class
    

    And in your other library:

    Dim objExcelReader : Set objExcelReader = New_ExcelFileReader
    objExcelReader.Init("D:\mytest.xlsx")
    

    Protip: You can pass initialization parameters into your constructor function.

    EDIT

    On request: how to pass constructor parameters. Just add them to your constructor function:

    Public Function new_ExcelFileReader2(filepath, sheetname)
        Set new_ExcelFileReader2 = new ExcelFileReader
        new_ExcelFileReader2.Init(filepath, sheetname)
    End Function
    
    ' And the call:
    Set myExcelFileReader = new_ExcelFileReader2("C:\temp\tempExcel.xlsx", "sheet1")
    

    In my implementation I have sometimes the same object, but that gets ‘configured’ by multiple contructor functions. In your case you could have a new_ExcelFileReader, a new_CSVFileReader and a new_TabDelimitedReader all pointing to the same object but configured differently.

    Another way to fancy up your code is to return the object (with the me keyword) by the init function. This will result in code like this:

    Class ExcelFileReader
    
        private filepath_
        public function Init(filepath)
            filepath_ = filepath
            Set Init = me
        end function
    
    End Class
    
    Set myExcelFileReader = new ExcelFileReader.Init("C:\temp\tmpExcel.xlsx")
    

    With a constructor function you can use it by just returning the object and then calling the Init function.

    Public Function new_ExcelFileReader()   ' this is the same as the first function
        Set new_ExcelFileReader = new ExcelFileReader
    End Function
    
    Set myExcelFileReader = new_ExcelFileReader.Init("C:\temp\tmpExcel.xlsx")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Git and just started to use Github. Just created my first public
I am new to QTP and I have a problem with error validation message.
New to Objective-C and iOS development, would love a hand here! I have written
new to JavaScript seeking some help. I have a form with a select drop
New to cpp (Java guy). I have 3rd party library that has method sendMail(txt).
I am super new to HP Qc and HP QTP. I have setup the
new on ruby and using windows xp and rails 3, i want to send
New to PHP and MySQL, have heard amazing things about this website from Leo
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I have my QTP Scripts in Test Scripts Tab and datasheets in the Attachment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.