• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

.bas Files and Class Files in VIsual Basic 6

Experts,

Is it not possible for the methods in a .bas file to be accessed from a class module in VB6?
0
NigelRocks
Asked:
NigelRocks
3 Solutions
 
Paul ThompsonIT ConsultantCommented:
Yes,

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.

DJ


0
 
hesCommented:
As long as the method is public YES
0
 
game-masterCommented:


yes is very possible..

and i have tried and tested it...


game-master
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now