Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a variable/constant value from a class module...

Status
Not open for further replies.

hogstrom

Programmer
Nov 24, 2009
12
SE
Hi,

I have a VBA code that miss some class modules. I know what the class modules are supposed to do so I'm currently trying to rebuld them. My problem is the following.

In Defenition Module
Public c As New wsConstants

In a seperate module I have the following code
NumOfMembers = .Cells(iRowTop, c.ClassDetail.memberColumn)

What do I write in the class module "ClassDetail"
I have tried the following

Option Explicit

Public memberColumn As Integer

Public Function ClassDetail() As Variant

memberColumn = 1

End Function

It is essential that I can use the "c.ClassDetail.memberColumn" string and get the value 1!

Is there someone who has any experience rearding this?
Thanks for any help!
 
What type of file is
Code:
Option Explicit

Public memberColumn As Integer

Public Function ClassDetail() As Variant

    memberColumn = 1

End Function

in? Is is a .bas module or .cls class?

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
The name of that file with be the class name then, let's say "SomeClass.cls". Given the code above you would access the "memberColumn" data member by declaring a varible of type "SomeClass" and using the "." to access it not through the "ClassDetail" function.
Code:
Public sc as SomeClass

sc.ClassDetail 'this will assign the memberColumn value
NumOfMembers = .Cells(iRowTop, sc.memberColumn) 'memberColumn will be 1

I am trying to piece together what you have from the code that you have given. If this doesn't make sense I will need some more detailed code samples and the file type it is contained in.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Ok let's see if I can explain better this time around!

This is the function (Just something I put together to illustrate)
Code:
Option Explicit
Public c As New wsConstants

Public Function membersnumber(member As Range, iRowTop As Integer)
Dim ws As Worksheet
Set ws = Activeworkbook.Worksheets("Members")
With ws
NumOfMembers = .Cells(iRowTop, c.ClassDetail.memberColumn)
End With
membersnumber=NumOfMembers
Exit function

Then I have a .cls with the name "wsConstants"
Code:
What should I put in here

memberColumn = 1

I guess I have to have a function or property with the name "classDetail" where I declare that memberColumn = 1?

I have a massive xla library with code that uses the ".Cells(somerow, c.somefunction.somecolumn)" that's why I need to learn what it does!

Thank you for your help, really helpful!
 
ClassDetail would need to be a member of wsConstants and memberColumn would need to be a member of ClassDetail.
Code:
'SomeClass.cls
Public memberColumn As Integer

Public Sub SetMemberColumn()
  memberColumn = 1
End Sub

the wsConstants.cls
Code:
Public ClassDetail as SomeClass

Public Sub SetValues
   ClassDetail.SetMemberColumn()
End Sub

Using your code
Code:
Option Explicit
Public c As New wsConstants

c.SetValues()

Public Function membersnumber(member As Range, iRowTop As Integer)
Dim ws As Worksheet
Set ws = Activeworkbook.Worksheets("Members")
With ws
NumOfMembers = .Cells(iRowTop, c.ClassDetail.memberColumn)
End With
membersnumber=NumOfMembers
Exit function

c is wsConstants class object
ClassDetail is a SomeClass object member contained in wsConstant class
and memberColumn is an integer member of SomeClass

Sometimes setting breakpoint and stepping throught the code helps as well.
Hope that sheds some light.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Thank you Foada, I finally got it to work!

Without yor help I would be stuck with this forever, finally I can put this behind me :D

Hopefully I can help you in return sometime!
 
No Problem. Glad to help.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top