PC Review


Reply
Thread Tools Rate Thread

Class Module Method

 
 
Matthew Pfluger
Guest
Posts: n/a
 
      23rd Apr 2008
I have a class module called CInertiaData that contains 6 double variable
declarations:

Public dmMass As Double
Public dmDensity As Double
Public dmVolume As Double
Public dmCOG_x As Double
Public dmCOG_y As Double
Public dmCOG_z As Double

I declare new instances of this module as follows:
Dim muInertiaData As CInertiaData
Set muInertiaData = New CInertiaData

At several points in my code, I want to reset all values in muInertiaData to
0. I'd like to write a method instead of a subroutine, but I'm not sure how
to proceed. I believe it would be something like:

Public Sub Clear(ByRef oInertiaData As CInertiaData)
On Error Resume Next
With oInertiaData
.dmMass = 0
.dmDensity = 0
.dmVolume = 0
.dmCOG_x = 0
.dmCOG_y = 0
.dmCOG_z = 0
End With
End Sub

However, this still requires passing a CInertiaData object to the method.
How do I write the method so it clears the CInertiaData object that calls it?
I would guess that this involves changing the way I define my Class Module
variables.

Thanks,
Matthew Pfluger
 
Reply With Quote
 
 
 
 
Andy Pope
Guest
Posts: n/a
 
      23rd Apr 2008
Hi,

You would make the Clear routine part of the class module.

Public Sub Clear()

dmMass = 0
dmDensity = 0
dmVolume = 0
dmCOG_x = 0
dmCOG_y = 0
dmCOG_z = 0

End Sub

And then in code you would use it something like this.

Option Explicit

Dim muInertiaData As CInertiaData

Sub Test()

Set muInertiaData = New CInertiaData

With muInertiaData
.dmMass = 10.3
.dmDensity = 2
.dmVolume = 12

Debug.Print "Before Clear", .dmMass, .dmDensity, .dmVolume

.Clear

Debug.Print "After clear", .dmMass, .dmDensity, .dmVolume

End With

End Sub

Cheers
Andy


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Matthew Pfluger" <(E-Mail Removed)> wrote in
message news:9E27CD50-10CF-47C9-BF58-(E-Mail Removed)...
>I have a class module called CInertiaData that contains 6 double variable
> declarations:
>
> Public dmMass As Double
> Public dmDensity As Double
> Public dmVolume As Double
> Public dmCOG_x As Double
> Public dmCOG_y As Double
> Public dmCOG_z As Double
>
> I declare new instances of this module as follows:
> Dim muInertiaData As CInertiaData
> Set muInertiaData = New CInertiaData
>
> At several points in my code, I want to reset all values in muInertiaData
> to
> 0. I'd like to write a method instead of a subroutine, but I'm not sure
> how
> to proceed. I believe it would be something like:
>
> Public Sub Clear(ByRef oInertiaData As CInertiaData)
> On Error Resume Next
> With oInertiaData
> .dmMass = 0
> .dmDensity = 0
> .dmVolume = 0
> .dmCOG_x = 0
> .dmCOG_y = 0
> .dmCOG_z = 0
> End With
> End Sub
>
> However, this still requires passing a CInertiaData object to the method.
> How do I write the method so it clears the CInertiaData object that calls
> it?
> I would guess that this involves changing the way I define my Class Module
> variables.
>
> Thanks,
> Matthew Pfluger


 
Reply With Quote
 
Matthew Pfluger
Guest
Posts: n/a
 
      23rd Apr 2008
Wow, I thought I had to send a reference to an object in order to run the
method. Thanks for setting me straight, Andy!

Matthew Pfluger

"Andy Pope" wrote:

> Hi,
>
> You would make the Clear routine part of the class module.
>
> Public Sub Clear()
>
> dmMass = 0
> dmDensity = 0
> dmVolume = 0
> dmCOG_x = 0
> dmCOG_y = 0
> dmCOG_z = 0
>
> End Sub
>
> And then in code you would use it something like this.
>
> Option Explicit
>
> Dim muInertiaData As CInertiaData
>
> Sub Test()
>
> Set muInertiaData = New CInertiaData
>
> With muInertiaData
> .dmMass = 10.3
> .dmDensity = 2
> .dmVolume = 12
>
> Debug.Print "Before Clear", .dmMass, .dmDensity, .dmVolume
>
> .Clear
>
> Debug.Print "After clear", .dmMass, .dmDensity, .dmVolume
>
> End With
>
> End Sub
>
> Cheers
> Andy
>
>
> --
>
> Andy Pope, Microsoft MVP - Excel
> http://www.andypope.info
> "Matthew Pfluger" <(E-Mail Removed)> wrote in
> message news:9E27CD50-10CF-47C9-BF58-(E-Mail Removed)...
> >I have a class module called CInertiaData that contains 6 double variable
> > declarations:
> >
> > Public dmMass As Double
> > Public dmDensity As Double
> > Public dmVolume As Double
> > Public dmCOG_x As Double
> > Public dmCOG_y As Double
> > Public dmCOG_z As Double
> >
> > I declare new instances of this module as follows:
> > Dim muInertiaData As CInertiaData
> > Set muInertiaData = New CInertiaData
> >
> > At several points in my code, I want to reset all values in muInertiaData
> > to
> > 0. I'd like to write a method instead of a subroutine, but I'm not sure
> > how
> > to proceed. I believe it would be something like:
> >
> > Public Sub Clear(ByRef oInertiaData As CInertiaData)
> > On Error Resume Next
> > With oInertiaData
> > .dmMass = 0
> > .dmDensity = 0
> > .dmVolume = 0
> > .dmCOG_x = 0
> > .dmCOG_y = 0
> > .dmCOG_z = 0
> > End With
> > End Sub
> >
> > However, this still requires passing a CInertiaData object to the method.
> > How do I write the method so it clears the CInertiaData object that calls
> > it?
> > I would guess that this involves changing the way I define my Class Module
> > variables.
> >
> > Thanks,
> > Matthew Pfluger

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help passing Range to Class Module method Brian Herbert Withun Microsoft Excel Programming 8 13th Feb 2008 03:53 AM
Difference between Form's Class Module and Class Module tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 4 14th Apr 2006 01:08 PM
Calling a module function from a class method ranafout Microsoft Excel Programming 1 12th Nov 2003 11:08 AM
Re: Subform Class Module Method call fails Jim C. Microsoft Access Form Coding 0 21st Aug 2003 04:45 PM
Re: Subform Class Module Method call fails Albert D. Kallal Microsoft Access Form Coding 1 21st Aug 2003 04:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.