Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2005, 11:09 AM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to pass values between class modules ?

other than by writing values in excel sheet? (i am talking about VBA in excel).
thank you.
yvon

 
Old December 7th, 2005, 05:13 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

First of all, there is no such concept as passing values between class modules. Class modules are (essentially) templates used for creating instances of the class described within them.
These instantiations of classes (called objects) have values, but the modules that describe how these instances should be created do not.
In the class module, create an exposed variable of the type of the other class that this class must work with.
Code:
     Public TheOther As clsTheOther
Create a method to do your manipulating.
Code:
Public Sub MakeChange()
    TheOther.ItsProperty = Me.MyProperty
End Sub
Then make an instance of both classes, set the public variable of the class I've shown the code of here to be a reference to the object that needs to be changed, then call the method.
Code:
  . . .
    Dim objWorker As New clsWorker
    Dim objWorked As New clsRecipient

    ' Set a reference. (There are now 2 references to the same object.)
    Set objWorker.TheOther = objWorked 

    objWorker.MakeChange              ' Do the work

    Set objWorker.TheOther = Nothing  ' Release the reference

  . . .
objWorked will now have the value that you set it up to receive, having come from the value you set up to send in objWorker.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Class modules lallemantdo Excel VBA 4 August 24th, 2005 08:35 PM
What is Meant by Instancing in Class Modules ramk_1978 VB Components 1 February 2nd, 2005 12:09 AM
how to pass multiple values throw url class object kfarooq Servlets 1 June 20th, 2003 04:06 AM
Class Modules ezzedin Beginning VB 6 2 June 9th, 2003 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.