473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2593
On Mon, 25 Jun 2007 23:47:59 -0000, otterbyte <ot*******@gmai l.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*******@gmai l.comwrote in
news:11******** **************@ o61g2000hsh.goo glegroups.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*******@gmai l.comwrote in
news:11******** **************@ c77g2000hse.goo glegroups.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
1825
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 do that. One way is to create new class as a local (automatic) variable in function and then to return it:
3
13349
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 the recordset object to the calling functions/procedures. I already tried this but keep getting error 13 (type mismatch). how can I achieve it? ...
2
2335
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 the class object. Is this possible?
9
2212
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 all have a different enumeration in them called Properties. I want to basically have a variable The_Class that I can dynamically point to either...
9
8307
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 download a file no problem. My issues come when I try to use the same class with the same commands to access an FTP server on a UNIX box. I can connect...
6
1700
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 subroutines, without having to redefine them every function/subroutine. I ran into a problem when trying to define a GridView in that FormView and I was...
9
2337
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 = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
3
4117
by: Matt | last post by:
Hi All, I have the current Sub Procedure in a VBA Module. ----------------------------------------------------------------------------------------------------------------------------- Sub openForm(formName As String, Optional varToSend As Object) If varToSend Is Missing Then DoCmd.openForm formName Else DoCmd.openForm formName, , , , ,...
1
1094
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 program: Dim WithEvents dsPerson As Person Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ...
0
7546
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6071
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.