I am trying to write a program that reads through a word document, examines tables, copies their contents to the clipboard and saves them into lists of lists:
List<List<Strin g>> and also one List<List<List< String>>>
Think of it kind of like filing intructions into a list of how to build a dining set or something. The set has different parts, which each will have their own instructions.
Dining Set
- Table
- Step 1 - put on legs
- Step 2 - place top on legs
- Chairs
- Step 1 - unpack cushion
- Step 2 - assemble back
and so on.. Where each step is a String.
I can get each step string and add it to a list of each part, but when I start on a new part, it overwrites the previous part.
So my instructions for say the table, will be output as the steps for the chairs. It basically makes everything equal to whatever the last part was. This I am assuming is because of memory pointing. Because I go and change stuff that other things reference, it it will change whatever it referencing it.
So my question is, Is there any way of getting around this? I was hoping that c# had an eval function that I could use in place of this, but none exist.
I feel like this may be a simple fix, but I just can not think of it currently.
Sample Output. Note: Each Case shoudl have differnet numbers of steps
Scenario 1
Case 1: 7 steps
Case 2: 7 steps
Case 3: 7 steps
Case 4: 7 steps
Case 5: 7 steps
Case 6: 7 steps
Case 7: 7 steps
Case 8: 7 steps
Case 9: 7 steps
Case 10: 7 steps
Case 11: 7 steps
Case 12: 7 steps
Scenario 2
Case 1: 12 steps
Case 2: 12 steps
Case 3: 12 steps
Case 4: 12 steps
Case 5: 12 steps
Case 6: 12 steps
Case 7: 12 steps
Case 8: 12 steps
Case 9: 12 steps
Case 10: 12 steps
Scenario 3
Case 1: 1 steps
Case 2: 1 steps
Case 3: 1 steps
Case 4: 1 steps
Case 5: 1 steps
Case 6: 1 steps
Case 7: 1 steps
Case 8: 1 steps
Case 9: 1 steps
Case 10: 1 steps
Case 11: 1 steps
9 1481
Without seeing your logic for adding steps to a relevant instruction it is hard to say what the problem actually is. If I were trying to solve this problem I would not use List<List<List< String>>>. This makes it very difficult to see where you are actually having a problem.
I would change this to a first class concept.
class Item
{
public void addSubItem(Item item)
{
}
public void addInstruction( String instruction)
{
}
private string name;
private List<Item> items; //the subitems that need to be constructed
private List<String> instructions; //the instructions for this item
}
So the Dining Set would contain in its list of items a Table and Chair.
You would have to write your more method using this concept, but it will be clearer to see what is going on.
@hype261
unfortunately I was told to use List<List<List< String>>> by the person who I amd doing this for. I am not particularly sure why, but ehh whatever.
When adding steps, I have a List like -
List<String> steps = new List<String>();
-
List<List<String>> cases = new List<List<String>>();
-
-
steps.add("case 1: Some string");
-
steps.add("case 1: Some other string");
-
-
cases.add(steps);
-
steps.Clear();
-
-
steps.add("case 2: Some string");
-
steps.add("case 2: Some other string");
-
cases.add(steps);
-
-
I clear out the steps list because case 2 has different steps from case 1.
That is how I am working that, and the problem is that case 1 will end up having the same steps as case 2. it overwrites them or changes the reference or something. Any suggestions with that?
@MZimmerman6
Basically your problem is what you believed.
When you add steps to to cases on line 7 you are just doing a shallow copy on to the list. That is you are just copy the address of the steps on the heap. So any modification you do to steps from this point on will affect the one stored in cases.
To get around this you need to make every step its own object by doing
List<String> steps = new List<String>();
I would suggest rolling the addition of steps into its own method
@hype261
Oh it already is its own method, do not worry, I just wrote a simplified version of what I am doing because there is a lot more.
But i am unsure exactly what you mean by making each step its own object.
is there any way to make a more "deep" copy of the contents. say copy the contents rather than the reference?
@MZimmerman6
When you do the following declaration. - List<String> steps = new List<String>();
What you are doing is creating an object of type List<String> on the heap. The variable steps just contains the address of that object that is on the heap.
So if your steps are in its own method. -
public List<String> addStep()
-
{
-
List<String> steps = new List<String>();
-
<----- get the data for the steps
-
return steps;
-
}
-
So to use this all you would have to do is @hype261
I had tried something very similar to that before hand thinking that a method would break the pointer issue, much to no success. I was/am still having the same issue.
@MZimmerman6
Could you post the method you are using to add a step to the cases?
tlhintoq 3,525
Recognized Expert Specialist
Since each thing is a subnode of the parent thing...
I would use a treeview and make each thing a treenode.
Your professor can live with the logic of what you are doing, so long as you make a function in the end that outputs to List<string> objects.
@tlhintoq
I got it working now. I ended up redoing the part where I add cases, declaring a new list each time, and it worked.
Note: Not for school, For work :]
Thanks for all of your help though!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bob Kochem |
last post by:
Can someone point me at a tutorial or other reference on how VB 5 &/or 6
consumes memory and what its limits are?
I have a program in VB5 that has been around a while and grown quite a bit.
I am starting to run into compile-time errors like "Too many local dynamic
variables" I fixed that one by re-declaring some variables as Static but I'm
shooting in the dark.
Where can I find the various ways VB consumes memory, and what limits it...
|
by: Jon Perez |
last post by:
POSH, found at poshmodule.sourceforge.net , lets you share
Python objects across processes like you would among threads
and not have to resort to IPC mechanisms.
Because separate processes do not share the GIL, this allows
them to be scheduled on multiple CPUs.
Is anyone out there using POSH and is it reliable enough for
production use? Any plans to incorporate it into the Python
distribution?
|
by: Bryan |
last post by:
I've been messing around with a C++ application on Xbox, and have been
encountering problems with my objects getting garbage collected when
they go out of scope, but before I'm actually done using them. I'm not
really familiar with how this works in C++, since I first learned C,
then Java, and never really spent a lot of time learning C++ other
than applying Java concepts to C++'s syntax. Here's my problem:
I have a function (doesn't...
|
by: brad |
last post by:
I have a SQL 2K job that retries a DTS package several times. This DTS
package, about midway through, has an Execute SQL task that calls a
stored procedure that does a mass update. When this task runs, the
mass update hangs. If I look at the update "Process" under "current
activity," it shows the CPU and I/O increasing (CPU got up to
4,000,000), but the memory was at 0. I eventually had to stop the job.
Why is this process showing...
|
by: Kenneth Baltrinic |
last post by:
I am trying to compare values coming out of a database record with known
default values. The defaults are in an array of type object (because they
can be of any basic data type, I am not working with weird stuff, just
strings, int, bools and DataTime values) My fields values for this record,
for convenience are also in an array of objects. Now I am trying to write
code like the following.
private void processData (object d, object a)...
| |
by: kevin goff |
last post by:
Does anyone know if asp.net will be able to use more memory if I upgrade to
a Extended 64 bit machine?
Thanks,
KG
|
by: mseeger |
last post by:
My concrete problem is this (it is a bit special, but there may be other
instances of it):
I'd like to create a class for vectors (say: Vector), exporting math. methods, say v.foo(...).
I'd like to implement 'operator()' s.t. I can treat parts of a vector in the same
way as a normal vector: if v.foo(...) works, so should v(rng).foo(...), where
rng is a range object. This should work even if 'foo' is a non-const method.
I do this by...
|
by: Lykins |
last post by:
We currently use Access 2003 in our company and have had this issues
from every version from Access 97 to 2003. We deal with large
databases and run a lot of queries over tables with millions of records
in them.
The problem comes in that when we pull a dataset out of a large table
we do not get the same result every time. Example is transaction count
for store 1 shows 3000 one time, the next run it is 3015, the next is
2089. All of...
|
by: ssylee |
last post by:
I am using mikroC to program some microcontroller code in C. However I
have come across of potential problem of bool type not being supported
from the compiler complaint on how I declared type bool variable. From
a forum thread that I've pulled out from mikroBasic, I realized that
bool type isn't fully supported. When programming in mikroC, I have
been getting an error message of "invalid expression" when I declared
a bool type variable,...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |