Weird Schrodingers behaviour on Class Variable

Multiverse

New Member
Joined
Nov 15, 2019
Messages
16
Hi All

I have a really strange behaviour going on with a Class. I have a variable of type double which I can access either through property get, or public function. When using the class from one module, the variable is retrieved as expected, but when using the class from another module, I get 0 returned.

So using the debugger, and looking at the property get (or the function), when I hover over the variable, the value is zero. Not what I expected, so I inspect in the locals window and find it has the value of 1 as expected. Now when I go back to the property get, doing nothing else but hover over the variable, the variable has changed value from 0 to 1. I'm totally puzzled as to why my code is struggling to return the value of the variable and why the value of the variable changes when I observe it's value in the locals window. And I also find it weird that in a different Module, the Class behaves as expected.

Any ideas?

VBA Code:
CLASS
Private cConsultant1TotalPercent As Double
Private cTotal5000to5020 As Double

Public Property Get Consultant1Fee() As Double
    Consultant1Fee = Round(cConsultant1TotalPercent * cTotal5000to5020, 2)
End Property

VBA Code:
MODULE

myOutputArray(i, 4) = myColl(n).Consultant1Fee
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

6StringJazzer

Well-known Member
Joined
Jan 27, 2010
Messages
865
Office Version
  1. 365
Platform
  1. Windows
When using the class from one module, the variable is retrieved as expected, but when using the class from another module, I get 0 returned.
Can you provide enough code so we can reproduce it? So far you have just shown one Get from one module. I would like to see the code from both modules, including all declarations, etc. If you provide enough code to reproduce the problem I will copy it into a file and see what happens when it runs.

The ideal solution would be for you to provide the file itself on a file-sharing service.
 

Forum statistics

Threads
1,137,117
Messages
5,679,716
Members
419,853
Latest member
hc9587

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
Top