473,322 Members | 1,690 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,322 software developers and data experts.

Strange Bug with the order of objects in a collection

I've come across a problem that I just cannot explain. I'm hoping that
someone has seen it before.

I have the following [basic] data structure:

Questions (collection)
Question (object)
Choices (collection)
Choice (object)
I populate Questions[0].Choices with 4 Choice objects - let's call them "A",
"B", "C", "D". They're inserted into the Choices collection in that
order. Then I rearrange the order this way: B C A D I pause
the program and use "QuickWatch" to confirm that the order has indeed
changed. Everything's fine so far.

Then I run a few more lines of code - none of which are changing this data
in ANY WAY and yet when I check back to look at Choices, the order has
changed to: A C A D

I couldn't believe this was happening!!! But I've checked it numerous times
and it IS happening! I've triple checked the lines of code and they are
definitely NOT touching this data model. It almost seems like that "B" is
being changed to an "A" after a certain length of time or else something
external is doing it. But it definitely isn't my code.

How on earth is this possible???
--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #1
2 915
First, you need to post the relevant code.

As a blind stab at a solution, I would ask whether it's not a reference
problem. To explain what I mean, here's an example:

Choice temp = new Choice("A");
questions[0].Choices.Add(temp);
temp = new Choice("B");
questions[0].Choices.Add(temp);
Choice temp2 = new Choice("C");
questions[0].Choices.Add(temp2);
temp2 = new Choice("D");
questions[0].Choices.Add(temp2);

.... now for the kicker ...

temp.ChoiceLetter = "A"; // or something like that

.... Hey! The "B" in the list changed to "A"! Of course, because I was
still holding a reference to the object I created and I modified it,
since the reference in the list points to the same object, it changed
"too" (it didn't change "too": there's only one of them).

Could it be something like that?

Anyway, you need to post the code. :-)

Nov 17 '05 #2
Thanks, Bruce. I actually had a reference problem a few weeks ago but this
time it was not that. About half an hour after posting and after talking
with a friend of mine, I discovered the culprit. I had sort of outsmarted
myself. I have built some pretty extensived automated update code that keeps
a form in sync with the data model. I call it "ASM". I didn't think this
was the cause because I was stepping through the code in question and it
wasn't showing me the execution of any ASM code.

But lo and behold it was firing! I still don't know why the debugger
doesn't show it normally but once I added a few breakpoints in the ASM code I
saw it was so.

So the solution was to temporarily disable this code, do the necessary
visual updates, and then reactivate the code.

Sorry to trouble you [all] but I was completely stymied ... and have learned
something new about the debugger!

Thank you again for your help.

--
Robert W.
Vancouver, BC
www.mwtech.com

"Bruce Wood" wrote:
First, you need to post the relevant code.

As a blind stab at a solution, I would ask whether it's not a reference
problem. To explain what I mean, here's an example:

Choice temp = new Choice("A");
questions[0].Choices.Add(temp);
temp = new Choice("B");
questions[0].Choices.Add(temp);
Choice temp2 = new Choice("C");
questions[0].Choices.Add(temp2);
temp2 = new Choice("D");
questions[0].Choices.Add(temp2);

.... now for the kicker ...

temp.ChoiceLetter = "A"; // or something like that

.... Hey! The "B" in the list changed to "A"! Of course, because I was
still holding a reference to the object I created and I modified it,
since the reference in the list points to the same object, it changed
"too" (it didn't change "too": there's only one of them).

Could it be something like that?

Anyway, you need to post the code. :-)

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
12
by: Jozef | last post by:
Hello, Does anyone here know for sure, when you do a For Each loop on a forms controls collection, does Access cycle through them in Alphabetical order or control ID or ???. Any ideas? ...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
4
by: William Sullivan | last post by:
I have an extremely weird problem that I have no idea how to approach. I have a simple page with a search textbox and a search button. The button causes a postback, where I perform the search and...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
0
by: Andreas | last post by:
Hi! I'm using a custom collection with custom items to be edited with a custom CollectionEditor. This set of functionality is to be a part of a plugin for a SharpDevelop-based application. The...
2
by: elaine | last post by:
I'm working on a .net web application. The architect of this web application is quite different than other web applications i worked before. Since we use a set of tools to generate most of the...
7
by: lothar.behrens | last post by:
Hi, I have figured out that .NET CLR implements object destruction on the knowledge of usage of these objects. My DBHelper class closes the connection when refcount goes to zero. That happens...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.