Declaring public variables

confusion123

Active Member
Joined
Jul 27, 2014
Messages
400
Is it good practice NOT to declare variables publically but instead define a class?

So in place of this in a standard module:

Code:
Public FileNumber As Integer

use this in MyClass

Code:
Private mintFileNumber As Integer

Public Property Get FileNumber() As Integer

    FileNumber = mintFileNumber

End Property

Public Property Let FileNumber(ByVal FNumber As Integer)

    mintFileNumber = FNumber

End Property

but I still need to add this in a standard module:

Code:
Global MyFileNumber As MyClass

Thanks
 
When you work with the Ribbon you often need to store a reference to the IRibbonUI object so that you can then invalidate controls or the whole ribbon in code (eg to refresh captions, lists, enabled/visible status). The problem is that any unhandled errors destroy your object reference so your code won't work (and you only get supplied the object in the ****** callback when the workbook is loaded). The only workaround I know of is storing the memory address and then using CopyMemory to restore it.

Anyway, this is both irrelevant and moot here. :)
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Haha that's horrible!! - Think I'm glad I haven't been subject to that gem, though I've done something similar before to sort out some circular references.

But why wouldn't it work? Having cast my eye over your code I don't see why it wouldn't work in this context. The class will get reinitialized if state is lost and called again - can't you just stuff the object hydrating code in the class init?
 
Upvote 0
Yes, but I was hoping this might have been a means to avoid the need for rehydration. :)
 
Upvote 0

Forum statistics

Threads
1,216,297
Messages
6,129,954
Members
449,544
Latest member
Akhil333

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top