Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro 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 May 17th, 2007, 09:03 AM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class: method or internal procedure ???

Hello,

This is probably more of a design question rather than a specific question about vb6.

I’m creating a class module with a number of property let and property get variables. The property let variables are used in a fairly complex spring formula and the output will be property get variables.

e.g.

Public Property Let TubeODInMM(TubeODInMM As Single)
vTubeODInMM = TubeODInMM
End Property
Public Property Let CurtainSectionThkInMM(CurtainSectionThkInMM As Single)
vCurtainSectionThkInMM = CurtainSectionThkInMM
End Property
Public Property Let CurtainWidthInMM(CurtainWidthInMM As Single)
vCurtainWidthInMM = CurtainWidthInMM
End Property

Public Property Get TorqueClosed()
TorqueClosed = vTorqueClosed
End Property
Public Property Get TorqueOpened()
TorqueOpened = vTorqueOpen
End Property
Public Property Get RadiusClosed()
RadiusClosed = vRadiusClosed
End Property
Public Property Get RadiusOpened()
RadiusOpened = vRadiusOpened
End Property

From a design point of view, is it better to let the user of the object set the input properties; execute a GetSpring() method and then read the output properties e.g.

Dim objSpring as New clsSpring

ObjSpring.TubeODInMM=127
ObjSpring.CurtainWidthInMM =2400
Etc.
ObjSpring.GetSpring()
VRadiusClosed= ObjSpring.RadiusClosed
VRadiusOpened= ObjSpring.RadiusOpened
Etc.

or set the input properties and automatically run internally in the object GetSpring() procedure when the user selects a output property e.g.

Dim objSpring as New clsSpring

ObjSpring.TubeODInMM=127
ObjSpring.CurtainWidthInMM =2400
Etc.
VRadiusClosed= ObjSpring.RadiusClosed
VRadiusOpened= ObjSpring.RadiusOpened
Etc.

Inside the class
Public Property Get TorqueClosed()
    Call GetSpring()
TorqueClosed = vTorqueClosed
End Property

Thanks


 
Old May 17th, 2007, 10:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

My point of view: if you call getspring in every property you will call it maybe more times that is needed, because if you want to read all the values you will call it every time it tries to read...

I prefer the first method: let the user call getspring and them let him choose which data he want.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 18th, 2007, 12:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

tough question.
Forcing the caller to call a method before accessing the output parameter can bring bad code errors.
You can use an internal variable (boolean) that is set to true every time a property changes, like

public property let ff(c)
m_changed = (c <> m_c)

and then in every property get you call GetSpring if m_changed is true (and set m_changed to false). In this way you call GetSpring only once, and the caller does not have to take any action

Personally, I prefer to have the caller to call explicitally a method to apply the new properties, like you are doing now

"There are two ways to write error-free programs. Only the third one works."
Unknown
 
Old May 18th, 2007, 03:44 AM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you both for your replies. I'll design the code based on your answers!






Similar Threads
Thread Thread Starter Forum Replies Last Post
access internal class by adding namespace shubhanker_techgeek General .NET 0 November 24th, 2008 08:49 AM
Can’t add method to class in C#? arbab BOOK: Beginning C# 2005 Databases 0 September 29th, 2008 07:35 AM
Instance of same class in main method ajit Java Basics 1 July 1st, 2006 06:26 PM
Method calls within same class w/Interface gmontanaro C# 0 April 6th, 2006 05:44 PM
calling private method from another class jack_3 C# 3 December 16th, 2005 07:56 PM





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