Click here to Skip to main content
15,908,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to develop a program where I need to store 1000 values in the main memory and then write them into a file but I am having a problem that I am not sure what it is.
While compiling the program I have utilized the services of List<> and Array but in both cases I can only access only 14 variable. The rest are labeled as ?,?, which means the system has no idea of the index and the data.
I have tried a lot to find the solution on the internet but cant find any help.
Really need a guidance.

Thanks,
Farrukh Javeid
Posted
Comments
Sergey Alexandrovich Kryukov 5-Nov-11 20:30pm    
What is "main memory"? Do you know that both array and list are reference types?
--SA
farrukh.javeid 5-Nov-11 20:33pm    
yes, but I can't figure out the error. There is no obvious reason for the error so that is why I posted it on the code project.
Sergey Alexandrovich Kryukov 5-Nov-11 20:35pm    
See my current answer, my comments and please explain what you do step by step if you want to get some explanation of what you see. Please make a simple code sample and show this code.
--SA
Sergey Alexandrovich Kryukov 5-Nov-11 20:32pm    
What is "labeled"? There is no such thing. Explain what do you mean. For this purpose, explain what you do step by step.
--SA
farrukh.javeid 5-Nov-11 20:45pm    
Well this the instantiation

//List<string> URL_List = new List<string>();
string[] URL_List = new string[1000];

and the part for inserting the values is

bool IsValid = true;

foreach (string curr in URL_List)
{
if (curr != null)
{
if (curr.Trim() != "")
{
if (curr == URL)
{
IsValid = false;
break;
}

}
else
{
IsValid = false;
}
}
}

if (IsValid == true)
{
//URL_List.Add(URL);
URL_List[ListCounter] = URL;
ListCounter++;
}

I am sorry the code looks a bit vague but I have tested the code by debugging it. The value is passed rightfully but is not inserted in the list or the array.

What you did is not clear, and, more importantly, what you say is not true. Accessing 1000 values is next to nothing; and you can always access them in the debugger as well. The problem could be in your values or how you interpret what you see. Your "system has no idea of the index and the data" sounds ridiculous to say the least.

—SA
 
Share this answer
 
Comments
farrukh.javeid 6-Nov-11 4:39am    
Hi,

Thanks for your time. I hope you have understood my problem by now. But I have checked the values myself. The values are extracted properly but when it comes to inserting the values, my system somehow forgets where it was.
Please check the screen shot of the problem:
http://www.postimg.com/image/52000/photo-51245.jpg

Thanks.
It seems clear that you want to:

1. create an Array or List to hold strings: string[], or List<string>.

2. pass in some string to a validation function that makes sure it is not null, not only whitespace, etc., and then insert the new string into the array or list after checking if it does not already match an existing string in the List or Array.

It can be this simple:
XML
private List<string> urlList;

private void Form1_Load(object sender, EventArgs e)
{
    urlList = new List<string>() {"0", "1", "2", "3", "4"};
}

private void AddURL(string theURL)
{
    // this will handle string is null, empty, or all white space
    if (String.IsNullOrWhiteSpace()) return;

    // prevent duplication
    if (urlList.Contains(theURL)) return;

    urlList.Add(theURL);
}
 
Share this answer
 
Comments
farrukh.javeid 6-Nov-11 4:37am    
Hi Bill,

Thanks for your time. This is a brilliant solution but I am still experiencing the same problem. Please check out the screen shot of the problem I am experiencing. I hope that will clear more things out.
http://www.postimg.com/image/52000/photo-51245.jpg

Right now this is for Array but same problem goes for List as well.
Looking forward to hear from you Bill.

Thanks.
BillWoodruff 6-Nov-11 5:32am    
Hi, I've looked at the screen shot, but I can't infer from knowing that for some reason you get nulls at positions #13 and #14 ... why that might be.

The only thing I can suggest is that you set a break-point on line #93 of your code, and then single-step from there, examining the value of 'temp in line #94, then single-stepping through each time 'AddToList is called.

best, Bill
farrukh.javeid 6-Nov-11 10:58am    
As much as it pains me to say that I have been there and I have done that but to no avail. Do you mind If I can send you the code so that you can check it yourself as well because I have checked everything in my knowledge, as well as all the suggestions that I receive.
BillWoodruff 8-Nov-11 1:35am    
Sorry, Farrukh, it's just not possible for me to review your actual code. best, Bill

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900