this is the problem
when this code is in the constructor the variable only lasts for that method (event) etc
the DIM makes this a local variable (local meaning ONLY in the event / method the code is in)
and at the end of this method its destroyed
anything with a DIM will live only as long as the method or event that contains that statement… as soon as the containing method completes, the DIM’d variable “dies”
I have
dbASPE as new aspeDB
in the constructer but getting compile error
mdGlobals.clRegPrice.Constructor, line 1
Can’t call something that isn’t a function
dbASPE as new aspeDB
[quote=428350:@Richard Albrecht]I have
dbASPE as new aspeDB
in the constructer but getting compile error
mdGlobals.clRegPrice.Constructor, line 1
Can’t call something that isn’t a function
dbASPE as new aspeDB[/quote]
my bad … copy & pasted
dbASPE as new aspeDB
should read
dbASPE = New aspeDB
sorry
EDIT : I fixed up my prior post with the wrong code so others will not make the same mistake
[quote=428362:@Richard Albrecht]In session open I have
Dim RegPrices As New mdGlobals.clRegPrice (mdGlobals is a module)[/quote]
This creates the instance and makes it only usable IN the open event
As Dave said this is the same issue as before
If you need to keep the RegPrices for the entire duration of this form then the form should have a property on it to hold this instance
And in the open event you do
RegPrices = New mdGlobals.clRegPrice
again note the missing DIM
This is all related to the concept of SCOPE (not the mouth wash)
Scope has to do with “visibility” or your ability to access properties (methods constants or just about anything else)
A quick example is code like
for i as integer = 1 to 10
dim d as new date
next
d.totalseconds = 0
In this case D does not exist AFTER the loop ends because - its gone “out of scope” and so it has been removed from memory and cannot be used outside the loop
This same principle applies to a method (event, getter or setter of a computed property, and other nestings of code)
Every IF THEN … ELSE … END IF creates a new scope level in the code following the IF THEN and ELSE portions
Same for every CASE in a select case statement
Every time you enter a new method (event etc) there is a new scope level
So this
for i as integer = 1 to 10
if true then
dim d as new date
end if
d.totalseconds = 0
next
will fail since d after the END IF no longer exists
The IF created a new scope level and when that scope level is exited the variable in that level no longer exist
variables that you declare in a module can be Global or Private (there is more but for now )
If you mark it Global then it can be accessed anywhere. If marked Private it can only be accessed by other members of THAT module (these apply not only to variables but to methods as well)
If they are defined with a DIM statement WITHIN a method (such as Open Event) they exist only for the lifetime of that method and can only be access by that method.
So SCOPE is like Real Estate, in that there are 3 important aspects … Location, Location, Location