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 6084789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:33:49+00:00 2026-05-23T11:33:49+00:00

the problem i am having is that i can get the file to ready

  • 0

the problem i am having is that i can get the file to ready but my read code only seems to read 1 value in a 2 value list.i am stumped as to where this is going wrong. code as follows :

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;

 namespace test
 {

public partial class Form1 : Form
{
    [Serializable]
    public class ore
    {
        public float Cost;

    }



    private List<ore> oreData = new List<ore>();
    private ore b1 = null;
    private ore b2 = null;
    public Form1()
    {
        InitializeComponent();
        b1 = new ore();
        b2 = new ore();
        oreData.Add(b1);
        oreData.Add(b2);

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        // 1st text box input is float
        float tempFloat;


        if (float.TryParse(textBox1.Text, out tempFloat))
        {
            oreData[0].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");



    }


    private void textBox2_TextChanged(object sender, EventArgs e)
    {
        // 2nd text box input is float
        float tempFloat;
        if (float.TryParse(textBox1.Text, out tempFloat))
        {
            oreData[1].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");


    }


    private void button1_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("ore.dat", FileMode.Create);
        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(fs, oreData);
        fs.Close();
    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        // 3rd text box 
    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {
        //4th text box
    }


    private void button2_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("ore.dat", FileMode.Open);
        BinaryFormatter bf = new BinaryFormatter();
        oreData = (List<ore>)bf.Deserialize(fs);
        fs.Close();

        if (oreData!=null)
        {
            if (oreData.Count > 0)
                textBox3.Text = oreData[0].Cost.ToString();//update the 3rd text box
            if (oreData.Count > 1)
                textBox4.Text = oreData[1].Cost.ToString();//update the 4th text box

        }
    }
}
}
  • 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-23T11:33:50+00:00Added an answer on May 23, 2026 at 11:33 am

    I found your problem! (Oh my eyes hurt!)

    Look at the if statement in your textbox1_changed and textbox2_changed methods. They are both

    if (float.TryParse(textBox1.Text, out tempFloat))
    

    But the second one should say

    if (float.TryParse(textBox2.Text, out tempFloat))
    

    Notice that textbox1 is changed to textbox2. This should solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Guys, Here I am having problem that How can I post an image
Here's the problem I'm having, I've got a set of logs that can grow
Hi all I am having some problems that I think can be attributed to
I am having problem that when i am trying to submit the form by
Hi The problem am having is that I have multiple TreeView control and each
The problem i'm having is that i've created a web service, and a windows
I'm trying to debug a cons script, and the problem I'm having is that
I am having the problem that I cannot select a specific XML node which
I am having a problem that just started happening in OS 3.1. I have
My problem is that I have a user that is having a problem displaying

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.