By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,616 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,616 IT Pros & Developers. It's quick & easy.

Class object losing data after call to subroutine

P: n/a
Hi,

I have a bit of code which is confusing me to no end. Here are the
basics:

1) The class module is being used in the module of a form.
2) There is an instance of the object declared at the form level, and
instantiated in the Load event of the form. This instance holds the
"current" values (based on data in a table), and it's called
ordCurrent.
3) If the values are then edited by the user, this calls an event
which creates a new instance of the class is and then instantiates it.
It's called ordEdit and contains the same data as ordCurrent. I don't
just copy ordCurrent into ordEdit, I get the values from the table
again so I have two separate pointers.
4) A few if/thens run to determine the correct subroutine (in another
module) to run at this point based on user settings
5) The proper subroutine is called
6) The rest of the code in the event runs

My problem happens between 5 and 6. Until this point, ordCurrent has
all its values and everything is fine. As soon as the subroutine runs,
however, all the data in ordCurrent are lost. The object still exists,
but all its properties are reset to default values (usually 0 or null
string, depending on the data type). None of the subroutines use
ordCurrent; it is only used in the form module.

Here's the weird part: if, when I'm debugging, I step through the
subroutine, instead of stepping over it, everything is fine. I'm not
doing anything else differently. Huh? Can someone please help me
figure out what might be going on?

Thanks!
Erika

ps - sorry for the lousy typing job, I'm holding a squirming baby in
the other hand. :)

Jun 25 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mon, 25 Jun 2007 23:47:59 -0000, otterbyte <ot*******@gmail.com>
wrote:

Would be hard to be sure without having the actual db here.
I might debug this by temporarily short-circuiting the subroutine
you're calling, by putting an "Exit Sub" in the first line. Just to be
really sure it's not causing the problem.
Also temporarily turn on "Break on all errors" in the Options screen,
just to be sure you don't have a lousy error handler tripping you up.
You are using the New keyword to create your object instances, right?

Not a bad typing job. My 9-week old typically runs over the keyboard
several times while I'm typing. I guess that's what kittens do :-)

-Tom.

>Hi,

I have a bit of code which is confusing me to no end. Here are the
basics:

1) The class module is being used in the module of a form.
2) There is an instance of the object declared at the form level, and
instantiated in the Load event of the form. This instance holds the
"current" values (based on data in a table), and it's called
ordCurrent.
3) If the values are then edited by the user, this calls an event
which creates a new instance of the class is and then instantiates it.
It's called ordEdit and contains the same data as ordCurrent. I don't
just copy ordCurrent into ordEdit, I get the values from the table
again so I have two separate pointers.
4) A few if/thens run to determine the correct subroutine (in another
module) to run at this point based on user settings
5) The proper subroutine is called
6) The rest of the code in the event runs

My problem happens between 5 and 6. Until this point, ordCurrent has
all its values and everything is fine. As soon as the subroutine runs,
however, all the data in ordCurrent are lost. The object still exists,
but all its properties are reset to default values (usually 0 or null
string, depending on the data type). None of the subroutines use
ordCurrent; it is only used in the form module.

Here's the weird part: if, when I'm debugging, I step through the
subroutine, instead of stepping over it, everything is fine. I'm not
doing anything else differently. Huh? Can someone please help me
figure out what might be going on?

Thanks!
Erika

ps - sorry for the lousy typing job, I'm holding a squirming baby in
the other hand. :)
Jun 26 '07 #2

P: n/a
The short-circuit was a great tip, thanks! I'm getting closer to the
actual problem...I don't know what's wrong yet, but at least I know
exactly *when* the problem happens, which is a lot better than
'somewhere in the subroutine'. :) I am using the New keyword, and not
instantiating my objects until just before using them. Although I did
discover I wasn't explicitly releasing the module-level object
(ordCurrent) when the form closed. Bad programmer! No biscuit! ;-)

Thanks for your help,
Erika

On Jun 26, 12:13 am, Tom van Stiphout wrote:
On Mon, 25 Jun 2007 23:47:59 -0000, otterbyte
wrote:

Would be hard to be sure without having the actual db here.
I might debug this by temporarily short-circuiting the subroutine
you're calling, by putting an "Exit Sub" in the first line. Just to be
really sure it's not causing the problem.
Also temporarily turn on "Break on all errors" in the Options screen,
just to be sure you don't have a lousy error handler tripping you up.
You are using the New keyword to create your object instances, right?

Not a bad typing job. My 9-week old typically runs over the keyboard
several times while I'm typing. I guess that's what kittens do :-)

-Tom
Jun 26 '07 #3

P: n/a
otterbyte <ot*******@gmail.comwrote in
news:11**********************@o61g2000hsh.googlegr oups.com:
My problem happens between 5 and 6. Until this point, ordCurrent
has all its values and everything is fine. As soon as the
subroutine runs, however, all the data in ordCurrent are lost. The
object still exists, but all its properties are reset to default
values (usually 0 or null string, depending on the data type).
None of the subroutines use ordCurrent; it is only used in the
form module
Put a breakpoint in both the class module's Initialize and Terminate
events. My bet is that it's being terminated somewhere and when you
check its values, you're re-initializing it. Do you have your
variable for this instance declared with the NEW keyword? If so,
that would give you what I just described.

Try removing the NEW keyword from class module instance declaration,
and instead explicitly instantiate it with Set myClass = New
clClass. Then you'll be able to see exactly where it's being
destroyed.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 26 '07 #4

P: n/a
otterbyte <ot*******@gmail.comwrote in
news:11**********************@c77g2000hse.googlegr oups.com:
I am using the New keyword, and not
instantiating my objects until just before using them.
Do you mean your variables are *not* decleared with NEW, but that
you explicitly create the instance with SET NEW?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 26 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.