Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:58:50+00:00 2026-05-28T05:58:50+00:00

Based on the function below, it is used to load data from file .dat.

  • 0

Based on the function below, it is used to load data from file .dat. The problem is every time i load a new file, the previous file will be overwritten. how to store the data from previous file inside the program so that when loading a new file, the new data will be added to the previous one?

private void btnLoad_Click(object sender, EventArgs e)
{
    try
    {

        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        openFileDialog1.Filter = "Data File (*.dat)|*.dat";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {

            TextReader f = new StreamReader(openFileDialog1.FileName);

            String line;

            this.letterData.Clear();
            this.letters.Items.Clear();

            while ((line = f.ReadLine()) != null)
            {
                int sampleSize = Form1.DOWNSAMPLE_HEIGHT * Form1.DOWNSAMPLE_WIDTH;
                char ch = char.ToUpper(line[0]);
                bool[] sample = new bool[sampleSize];

                int idx = 2;
                for (int i = 0; i < sampleSize; i++)
                {
                    if (line[idx++] == '1')
                        sample[i] = true;
                    else
                        sample[i] = false;
                }

                this.letterData.Add(ch, sample);
                this.letters.Items.Add("" + ch);
            }

            f.Close();
        }
        MessageBox.Show(this, "File Loaded");

    }
    catch (Exception ex)
    {
        MessageBox.Show("Error: " + ex.Message);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:58:50+00:00Added an answer on May 28, 2026 at 5:58 am

    Remove the following lines?

    this.letterData.Clear();
    this.letters.Items.Clear();
    

    EDIT:

    Or change to te following in order to have unique keys in your dictionary

    this.letterData.Add(string.Format("{0}_{1}", openFileDialog1.FileName, ch), sample);
    this.letters.Items.Add(ch.toString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function TRANSLATE which reads value from the xml file based on
How can I get a user-defined function to re-evaluate itself based on changed data
I have a php page that pulls data from a mysql database based on
I have problem removing rows from a table according to the checkbox. Below is
With the below function is based on the 0MQ Haskell bindings. I get an
This question uses jquery. In the card game below, one image will be used
Need to call a filter function on some options based on a radio selected
Is there some inbuilt function to return weekdayname based on value 1-7? /M
I want to write a function in Python that returns different fixed values based
I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.