Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Class Module Method

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Class Module Method

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" wrote in
message ...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Class Module Method

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" wrote in
message ...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help passing Range to Class Module method Brian Herbert Withun Excel Programming 8 February 13th 08 03:53 AM
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Class Module vs Normal Module Les Excel Programming 2 July 20th 07 09:54 AM
Calling a module function from a class method ranafout[_2_] Excel Programming 1 November 12th 03 11:08 AM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"