.bas Files and Class Files in VIsual Basic 6

Posted on 2009-12-19
Last Modified: 2012-05-08

Is it not possible for the methods in a .bas file to be accessed from a class module in VB6?
Question by:NigelRocks
    LVL 3

    Accepted Solution


    Try this:

    This is a button click event in a Form.
    Private Sub Command1_Click()
        Dim MyClass As clsMyClass
        Set MyClass = New clsMyClass
        MsgBox MyClass.GetModVar
    End Sub

    This is a function in a class object called clsMyClass.
    Public Function GetModVar() As String
        GetModVar = GetStr()  'calls Mod function
    End Function

    This is a method in a Module (any name)
    Public Function GetStr() As String
        GetStr = "Hello World"
    End Function

    The button click instantiates the class and calls the GetModVar method

    The GetModVar calls the GetStr method in the Module.

    The Module returns "Hello World to the class.

    The Class returns "Hello World" to the button click event where it is displayed.

    Hope this helps.


    LVL 24

    Assisted Solution

    As long as the method is public YES
    LVL 13

    Assisted Solution


    yes is very possible..

    and i have tried and tested it...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now