Solved

How to transfer the values from on class module to another class module

Posted on 2001-07-12
25
320 Views
Last Modified: 2013-11-23
I got a problem:

My problem is:

I have a form1 which has fields like text boxes and comboboxes and i'm passing the form1 values to a classmodule called class1 by using Let and Get properties, i'm getting the form1 values into this class module(class1) using Let and Get properties, my problem is i want to transfer this values from class1 module to another class module called class2. In class2 i'm writing a procedure like
public sub save()
'Here i want to get the form values from class1.

End Sub

I hope you understand the question. I don't want to use
.BAS module in my application, how to acheive this.

0
Comment
Question by:vmandem
  • 10
  • 9
  • 5
  • +1
25 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6277184
public sub save(oC1 as Class1)
'Here i want to get the form values from class1.
  zzz = oC1.zzz
'....etc.
End Sub
0
 

Author Comment

by:vmandem
ID: 6277336
I'm getting the result and i got little problem that when i call this procedure save in the form1 it is giving me error that Argument not optional.

I initialized the class module in the form load event, please help me on this, i will accept ur answer definetly.

Thankyou
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6277393
Can you show your code and where you are getting the error?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6277398
that when i call this procedure save in the form1 it
is giving me error that Argument not optional.


You have to call it and pass it an instance of class1, but please show me the code.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6277449
Sounds like you need some inheritance.  Look into the "Implements" statement.
0
 

Author Comment

by:vmandem
ID: 6277487
Yes paul, here is what i'm doing:

Before i explain let me say this:

I have a bas module called bas1.bas in that i'm declaring

public Newclass1 as class1
public Newclass2 as class2

Then coming to form load event i'm initializing like:

If Newclass1 is nothing then
set Newclass1 = New class1
end if

and same for Newclass2.

Then coming form: private sub cmdsave_click()
I'm doing like

Newclass1.employee1 = employee.text1
--I'm doing some mapping the values coming from the screen.
The Newclass1.employee1 is coming from class module class1.

Then i'm calling the procedure:

Newclass2.save

End sub

I'm getting error at Newclass2.save saying argument not optional.
"SAVE" is the procedure in class module class2.
What i'm doing wrong.

Thankyou
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 50 total points
ID: 6277510
If you took the advice I gave you above, you will have to call it like this:

Newclass2.save Newclass1

passing the object into the save routine as a parameter.
0
 

Author Comment

by:vmandem
ID: 6277622
Thanks paul, it works. I thank Dave too for his comment.

Thankyou once again for your help.
0
 

Author Comment

by:vmandem
ID: 6277629
Thankyou paul. Thanks for dave comment also.

bye
VMandem
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6277680
I believe we cured the symptoms not the illness with this one.  But inheritance is an advanced topic for most.

Glad you got it working!

:)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6277716
Hmm Dave, inheritance is not always warranted (In fact the way it is implemented in VB, it is usually more of a pain than a help.)  We don't know the relationship between class1 and 2 at all, they could be totally different things, but class 2 needs some of the info from class1 for the saving..
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6277743
If class2 always needs info from class1 then inherirance should be used.  that simple...  That's why you never see a class being passed as a parameter in good coding methodologies.  But like I said, if it works and is well commented, (and I don't have to maintain it) ...  Great
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 38

Expert Comment

by:PaulHews
ID: 6277882
So let's say I have a clsLogFile that does app logging and another class called clsSettings that has application settings.  The logfile class uses some of the settings (paths and stuff) and never changes from app to app.  The settings class has some properties that never change and others that are specific to the application.  (This is a file that implements a interface iSettings.)  So how would you do this using inheritance only?  If you implement iSettings in the logfile class, aren't you duplicating code unnecessarily?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6277945
You break it into manageable objects.  The properties that never change get broken up into their own whatever (Class, Module) doesn't matter the contents are contsant.  The Properties which are application specific go in their own class and are inherited by the log class.  No duplication, just plain object modeling.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6278154
OK Dave, I am trying to learn about object oriented design.  Been on my own a lot, as college gave some *very* sketchy details.  For me, learning about this is worth points as in, "Points for Dave_Green" 50, 100 whatever it is worth.  I think it is OK to keep it in this question since as you indicate it would have some value in the PAQ.  

>>>
You break it into manageable objects.  The properties that never change get broken up into their own
whatever (Class, Module) doesn't matter the contents are contsant.  <<<

So now I have a class for "always" settings as well as application specific settings where before I had a single class.  How does that make my code more maintainable?  

>>>
The Properties which are application
specific go in their own class and are inherited by the log class.  No duplication, just plain object
modeling.
<<<

The Logfile class uses the "always" settings, but not all of them.  So now any class that uses the always settings has to implement that interface?  Why is that desirable, if I only need some of the settings?  I wanted to separate the function of logfile from the function of saving, retrieving and making settings available, but now every module that uses any of the settings will have that ability built in, and will have to implement the interface for *all* the settings, not just the ones they need.  I see that as messy and less maintainable.

As the interface doesn't contain any code, I still have to delegate to common code if I want it, (which in this case is a must.)  Common code will have to go in a module (unless you know another way), which is another file I have to maintain.  
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278246
<??>So now I have a class for "always" settings as well as application specific settings where before I
had a single class.  How does that make my code more maintainable?<??>

Maintainabitlity is not the goal with this methodology.  Although if designed properly maintenance is not a problem.  The goal is code reuse, by defining reusable objects.

If you are going to share the "always" settings between applications, I would suggest creating a separate DLL which can be read into each application.  Hence, something changes, you have one component to rebuild and you are golden.  v.s. having a module or class which would cause you to rebuild each component or app which uses the info. (this part fixes the maintenance problem)

<??>The Logfile class uses the "always" settings, but not all of them.  So now any class that uses the always
settings has to implement that interface?  Why is that desirable, if I only need some of the settings?
 I wanted to separate the function of logfile from the function of saving, retrieving and making settings
available, but now every module that uses any of the settings will have that ability built in, and will
have to implement the interface for *all* the settings, not just the ones they need.  I see that as
messy and less maintainable.<??>

FIXED!  You are not inheriting fixed values, that would be a problem.

<??>As the interface doesn't contain any code, I still have to delegate to common code if I want it, (which
in this case is a must.)<??>
 
Not sure what you mean by the above statement. But I can tell you this.  Some of the best interface classes have little or no code in them.  

<??>Common code will have to go in a module (unless you know another way), which
is another file I have to maintain.<??>

If you have common processes you should consider putting them into a utility DLL for all of your applications to access.  (maintenance and reuse)



0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6278497
The DLL solution for code reuse would be nice, except that when the interface is changed there, you break compatibility.  Then you've lost your advantage, because I have to redistribute a completely new system of applications when that happens.  Right now, if I need a change in my utility library for a few exes in my system, I only need to deploy those few exes.  This is a big advantage in our business where we have remote installations all over North America.  For us the DLL solution is a nice idea, but the "gotcha" is a big one.

>>FIXED!  You are not inheriting fixed values, that would be a problem.<<

What are you talking about here?  I have a group of settings that are shared.  Different modules and objects need them.  The code remains the same across all my projects.  If I pass the object into another object as a parameter, I can use the settings I want very easily.  If I implement the interface of the settings class in every class that I want to use the object in, then I am creating very messy classes that have nothing to do with the original intent of the class.




>>Not sure what you mean by the above statement. But I can tell you this.  Some of the best interface
classes have little or no code in them.   <<

Yes, if it is an abstract class there is no code.  If there is shared code, i have to either delegate to a contained object or bas module instead of it being done automatically (as it would be in a C++ class.)  I guess what it comes down to is that I don't like the implementation of OO that VB uses in this incarnation.



0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278560
<??>The DLL solution for code reuse would be nice, except that when the interface is changed there, you
break compatibility.  Then you've lost your advantage, because I have to redistribute a completely new
system of applications when that happens.  Right now, if I need a change in my utility library for a
few exes in my system, I only need to deploy those few exes.  This is a big advantage in our business
where we have remote installations all over North America.  For us the DLL solution is a nice idea,
but the "gotcha" is a big one.<??>

You never have to break compatibilty.  You can append to the current functionality, as long as you don't change the interface you can keep BC forever.  Just like MS does for years on end.  In the past I have kept some interfaces and simply commented or got rid of the code inside them to keep BC.  Not wholy desirable, but think of the alternative.

<??>If I implement the interface of the
settings class in every class that I want to use the object in, then I am creating very messy classes
that have nothing to do with the original intent of the class.<??>

Again, you are falling into the old way of thinking.  If it becomes messy, it is because of the design.  P.S. I am not recommending that you change your current system!  You can only use this methodology when you can start from scratch.  Once a system has been implemented it becomes "messy" to change it.

<??>I guess what it comes down to is that I don't like the implementation of OO that VB uses in
this incarnation.<??>

It's not the implementation, it's the design.  With a poor design it does become difficult to understand what if any value you are gaining from it.

I've architected 3 major systems using this methodology.  Difficult at first for programmers to grasp, but once the light comes on... you've got yourself a worldclass solution.

0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6278627
OK, I like what we have so far.. 50 pts. <meter running...>


>>  In the past I have
kept some interfaces and simply commented or got rid of the code inside them to keep BC.  Not wholy
desirable, but think of the alternative.<<

Yes, I can see this.  I wasn't really 100% sure you could just keep adding to the interface, so that is good to know.  I guess if you had to modify an existing interface, you would just redefine it, add it on and modify the client to match (not that that would happen often, but if it did we would have to be able to keep compatibility.)

>It's not the implementation, it's the design.

OK, I still don't like the way VB does inheritance, it seems like a kludge to me, I'm sure VB.NET will be better in this regard.  So explain to me how you go about designing an OO solution, maybe give me a simple example that shows the code reuse benefits.  I've read the MSDN example and I'm familiar with the way objects model real life concepts (the classic Employee class for example.)  But how do you plan out how the objects communicate with each other.  And how does that work with inheritance if the objects are unrelated?

And why is it wrong to pass one object to another as a parameter?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278731
<??>But how do you plan out how the objects communicate with each other.<??>  

By building both your data, and object models you can readily see which objects will communicate with each other.  Then you derive your dataclasses from your data / object model. Continually keeping an eye out for duplicates (opportunities, to inherit another objects attributes)  Keep breaking down your models until every piece of communication and data have a home, and there is NO Duplication of the same entity. (This doesn't mean that you have an inherited object called phone number...  I'm sure you get my drift.)

<??>And how does that work with inheritance if the objects
are unrelated?<??>

If the objects are unrelated, inheritance is not an issue, not even a consideration.

<??>And why is it wrong to pass one object to another as a parameter?<??>

It wouldn't be a problem if it was solely a dataclass, and you were sending it to be saved by a class that handled the saving of all data objects.  But if you are sending a class just to get some data members out of it, it doesn't make much sense... from a design perspective anyway

 
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6278804
And for 100 pts, can you give me some titles of good books or useful links on OO design?  (You've earned it already, but I would like somewhere to go to follow up on this.)
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278817
Sure, I know of one title, let me see if I can find it online.. one sec.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278881
Here is a good book I have mostly finished...  I think it will get you where you want to be, as far as the underlying concepts.

http://www.amazon.com/exec/obidos/tg/stores/detail/-/books/020163385X/customer-reviews/qid=994970991/sr=1-14/ref=sc_b_14/104-0155309-7815970

Cheers, Just look me up if you have a specific Question.

DGreene2571@home.com
0
 

Author Comment

by:vmandem
ID: 6278931
Guys you have lot of discussion going on. Can you please tell me how to implement inheritance in my question if you don't mind.

Thankyou
Vmandem
0
 
LVL 15

Expert Comment

by:ameba
ID: 6279046
Another book for Paul (5 MB .pdf files) http://labsoftware.com/vbpatterns/vbPatterns.htm
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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

18 Experts available now in Live!

Get 1:1 Help Now