473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Class object losing data after call to subroutine

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
4 2576
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Milan Gornik | last post by:
Hello to all, My question is on right way of returning newly created class from a function (and thus, from class method or operator). As I currently see it, there are two different ways to...
3
by: JingleBEV | last post by:
Hi all, I am trying not to use global variable to maintain data consistency. Some procedures and functions will require to pass the recordset object for processing and functions may also return...
2
by: Steve | last post by:
Hello, If I instantiate a class object from a form I would like to be able to write to a label on the calling form something like "hello from class object" from within a subroutine inside...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
6
by: MRW | last post by:
Hello! I have a problem, I can't seem to solve. I'm making a class in my page that will hold the members of a FormView, so I can access them freely throughout the several functions and...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
3
by: Matt | last post by:
Hi All, I have the current Sub Procedure in a VBA Module. ----------------------------------------------------------------------------------------------------------------------------- Sub...
1
by: ggraham | last post by:
I'm a semi-newbie to .NET. I've create a class to handle getting data on a person. It has a couple of properties and a new and save subroutine. I'm loading the data in the page_load even of my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.