Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Save/Load Class

Save/Load Class

Scheduled Pinned Locked Moved C#
questioncsharplinqgraphics
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Q12_
    wrote on last edited by
    #1

    I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

    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 SaveLoadNamespace;
    using WarningsNamespace;
    using System.Text.RegularExpressions;

    namespace test7
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    SaveLoadClass slc = new SaveLoadClass();
    WarningsClass wc = new WarningsClass();

        string tampon;
        private void buttonSave\_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                tampon = "checkBox = true" + "\\r\\n";
            }
            else
            {
                tampon = "checkBox = false" + "\\r\\n";
            }
    
            tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
            tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
    
            slc.file\_SaveFile(tampon); label2.Text = wc.w2;
    
        }
    
        string buffer, s = ""; int i, j = 0;
        private void buttonLoad\_Click(object sender, EventArgs e)
        {
            //STRING MANIPULATION !!!
            slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
    
            #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
            //NumericUpDown
            if (buffer.Contains("numericUpDown"))//if that,then should goto there
            {
                i = buffer.IndexOf("numericUpDown");
                s = buffer.Remove(0, i); //remove the Begining of string
                if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                {
                    i = s.IndexOf("\\r\\n");
                    j = s.Length - i;
                    s = s.Remove(i, j);
                }
                if (s.Contains("="))
                {
                    i = s.IndexOf("=") + 1;
                    s = s.Remove(0, i).Trim();
                }
    
                i = int.Parse(s);
                numericUpDown1.Value = i;
            }
            #endregion >NumericUpDown-END<
    
    S R C _ 5 Replies Last reply
    0
    • _ _Q12_

      I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

      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 SaveLoadNamespace;
      using WarningsNamespace;
      using System.Text.RegularExpressions;

      namespace test7
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }
      SaveLoadClass slc = new SaveLoadClass();
      WarningsClass wc = new WarningsClass();

          string tampon;
          private void buttonSave\_Click(object sender, EventArgs e)
          {
              if (checkBox1.Checked)
              {
                  tampon = "checkBox = true" + "\\r\\n";
              }
              else
              {
                  tampon = "checkBox = false" + "\\r\\n";
              }
      
              tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
              tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
      
              slc.file\_SaveFile(tampon); label2.Text = wc.w2;
      
          }
      
          string buffer, s = ""; int i, j = 0;
          private void buttonLoad\_Click(object sender, EventArgs e)
          {
              //STRING MANIPULATION !!!
              slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
      
              #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
              //NumericUpDown
              if (buffer.Contains("numericUpDown"))//if that,then should goto there
              {
                  i = buffer.IndexOf("numericUpDown");
                  s = buffer.Remove(0, i); //remove the Begining of string
                  if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                  {
                      i = s.IndexOf("\\r\\n");
                      j = s.Length - i;
                      s = s.Remove(i, j);
                  }
                  if (s.Contains("="))
                  {
                      i = s.IndexOf("=") + 1;
                      s = s.Remove(0, i).Trim();
                  }
      
                  i = int.Parse(s);
                  numericUpDown1.Value = i;
              }
              #endregion >NumericUpDown-END<
      
      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, you could build a method to which you can pass a form. To get the controls at the passed form use the Controls-Property: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx[^] Check the type of each control to get the name like 'checkBox' for your string. Btw: Instead of using the type-name of each control I would suggest using the ID, so that you can store more than one checkbox for example. Hope this helps you a bit. Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      _ 1 Reply Last reply
      0
      • S SeMartens

        Hi, you could build a method to which you can pass a form. To get the controls at the passed form use the Controls-Property: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx[^] Check the type of each control to get the name like 'checkBox' for your string. Btw: Instead of using the type-name of each control I would suggest using the ID, so that you can store more than one checkbox for example. Hope this helps you a bit. Regards Sebastian

        It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

        _ Offline
        _ Offline
        _Q12_
        wrote on last edited by
        #3

        Its a good suggestion and i understand it because i see it some time ago used by others ... But, its too advanced for me for the moment and I wish to make it in some limited way that i can understand what i write there... But,I will look into it and I will strive to understand it how its done and try to use it...but small chance for me to accomplish that kind of maneuverability. Thanks

        _ 1 Reply Last reply
        0
        • _ _Q12_

          Its a good suggestion and i understand it because i see it some time ago used by others ... But, its too advanced for me for the moment and I wish to make it in some limited way that i can understand what i write there... But,I will look into it and I will strive to understand it how its done and try to use it...but small chance for me to accomplish that kind of maneuverability. Thanks

          _ Offline
          _ Offline
          _Q12_
          wrote on last edited by
          #4

          My idea is to make some overloads methods for: [int,string,bool](i suppose even for a object but is a to high standard for me). What do you think?

          1 Reply Last reply
          0
          • _ _Q12_

            I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

            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 SaveLoadNamespace;
            using WarningsNamespace;
            using System.Text.RegularExpressions;

            namespace test7
            {
            public partial class Form1 : Form
            {
            public Form1()
            {
            InitializeComponent();
            }
            SaveLoadClass slc = new SaveLoadClass();
            WarningsClass wc = new WarningsClass();

                string tampon;
                private void buttonSave\_Click(object sender, EventArgs e)
                {
                    if (checkBox1.Checked)
                    {
                        tampon = "checkBox = true" + "\\r\\n";
                    }
                    else
                    {
                        tampon = "checkBox = false" + "\\r\\n";
                    }
            
                    tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
                    tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
            
                    slc.file\_SaveFile(tampon); label2.Text = wc.w2;
            
                }
            
                string buffer, s = ""; int i, j = 0;
                private void buttonLoad\_Click(object sender, EventArgs e)
                {
                    //STRING MANIPULATION !!!
                    slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
            
                    #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
                    //NumericUpDown
                    if (buffer.Contains("numericUpDown"))//if that,then should goto there
                    {
                        i = buffer.IndexOf("numericUpDown");
                        s = buffer.Remove(0, i); //remove the Begining of string
                        if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                        {
                            i = s.IndexOf("\\r\\n");
                            j = s.Length - i;
                            s = s.Remove(i, j);
                        }
                        if (s.Contains("="))
                        {
                            i = s.IndexOf("=") + 1;
                            s = s.Remove(0, i).Trim();
                        }
            
                        i = int.Parse(s);
                        numericUpDown1.Value = i;
                    }
                    #endregion >NumericUpDown-END<
            
            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            What possessed you to declare a local variable called tampon? /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            _ 1 Reply Last reply
            0
            • R Ravi Bhavnani

              What possessed you to declare a local variable called tampon? /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              _ Offline
              _ Offline
              _Q12_
              wrote on last edited by
              #6

              I was actually thinking on "TRAIN Buffer" ,but in my language "tampon" actually is the word for "TRAIN Buffer"or 1.damper,2. bumper,3. fender, 4. shock, 5. buffer. I was not thinking at all at other meanings other than what i described ... sorry if i mislead you. I will change his name soon.

              R 1 Reply Last reply
              0
              • _ _Q12_

                I was actually thinking on "TRAIN Buffer" ,but in my language "tampon" actually is the word for "TRAIN Buffer"or 1.damper,2. bumper,3. fender, 4. shock, 5. buffer. I was not thinking at all at other meanings other than what i described ... sorry if i mislead you. I will change his name soon.

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                That's OK - it just made me laugh.  :) /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                1 Reply Last reply
                0
                • _ _Q12_

                  I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

                  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 SaveLoadNamespace;
                  using WarningsNamespace;
                  using System.Text.RegularExpressions;

                  namespace test7
                  {
                  public partial class Form1 : Form
                  {
                  public Form1()
                  {
                  InitializeComponent();
                  }
                  SaveLoadClass slc = new SaveLoadClass();
                  WarningsClass wc = new WarningsClass();

                      string tampon;
                      private void buttonSave\_Click(object sender, EventArgs e)
                      {
                          if (checkBox1.Checked)
                          {
                              tampon = "checkBox = true" + "\\r\\n";
                          }
                          else
                          {
                              tampon = "checkBox = false" + "\\r\\n";
                          }
                  
                          tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
                          tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
                  
                          slc.file\_SaveFile(tampon); label2.Text = wc.w2;
                  
                      }
                  
                      string buffer, s = ""; int i, j = 0;
                      private void buttonLoad\_Click(object sender, EventArgs e)
                      {
                          //STRING MANIPULATION !!!
                          slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
                  
                          #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
                          //NumericUpDown
                          if (buffer.Contains("numericUpDown"))//if that,then should goto there
                          {
                              i = buffer.IndexOf("numericUpDown");
                              s = buffer.Remove(0, i); //remove the Begining of string
                              if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                              {
                                  i = s.IndexOf("\\r\\n");
                                  j = s.Length - i;
                                  s = s.Remove(i, j);
                              }
                              if (s.Contains("="))
                              {
                                  i = s.IndexOf("=") + 1;
                                  s = s.Remove(0, i).Trim();
                              }
                  
                              i = int.Parse(s);
                              numericUpDown1.Value = i;
                          }
                          #endregion >NumericUpDown-END<
                  
                  C Offline
                  C Offline
                  c0ax_lx
                  wrote on last edited by
                  #8

                  Congratulations on getting your code to work :) This approach isnt very dynamic tho and if you add or remove fields you would have to modify your save/load methods. I suggest that you read some articles about Serialization. Start with XML serialization, that way you can open the xml file in your browser and see everything. binary serialization isnt very fun to look at :].

                  A FOO walked into a BAR, and the horse said..

                  1 Reply Last reply
                  0
                  • _ _Q12_

                    I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

                    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 SaveLoadNamespace;
                    using WarningsNamespace;
                    using System.Text.RegularExpressions;

                    namespace test7
                    {
                    public partial class Form1 : Form
                    {
                    public Form1()
                    {
                    InitializeComponent();
                    }
                    SaveLoadClass slc = new SaveLoadClass();
                    WarningsClass wc = new WarningsClass();

                        string tampon;
                        private void buttonSave\_Click(object sender, EventArgs e)
                        {
                            if (checkBox1.Checked)
                            {
                                tampon = "checkBox = true" + "\\r\\n";
                            }
                            else
                            {
                                tampon = "checkBox = false" + "\\r\\n";
                            }
                    
                            tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
                            tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
                    
                            slc.file\_SaveFile(tampon); label2.Text = wc.w2;
                    
                        }
                    
                        string buffer, s = ""; int i, j = 0;
                        private void buttonLoad\_Click(object sender, EventArgs e)
                        {
                            //STRING MANIPULATION !!!
                            slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
                    
                            #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
                            //NumericUpDown
                            if (buffer.Contains("numericUpDown"))//if that,then should goto there
                            {
                                i = buffer.IndexOf("numericUpDown");
                                s = buffer.Remove(0, i); //remove the Begining of string
                                if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                                {
                                    i = s.IndexOf("\\r\\n");
                                    j = s.Length - i;
                                    s = s.Remove(i, j);
                                }
                                if (s.Contains("="))
                                {
                                    i = s.IndexOf("=") + 1;
                                    s = s.Remove(0, i).Trim();
                                }
                    
                                i = int.Parse(s);
                                numericUpDown1.Value = i;
                            }
                            #endregion >NumericUpDown-END<
                    
                    _ Offline
                    _ Offline
                    _Q12_
                    wrote on last edited by
                    #9

                    I think I made it how I like it the most and i can proudly name it that is all right ... 2 nights over this but I bring it down right where I want it to be. Phew. Now I am happy with it. I know i must learn and assimilate /the faster the better/ the arrays and lists that you all master them soooo well, and i am angry for that, but... i will. About this matter, some good exercises that cant be done without them(arrays&lists&othersLikeThem) ,and who can be done without make me thinking about what I know already but direct me to learn them well? Thanks,and I appreciate. So, here is my Class:

                    using System.Windows.Forms;
                    using SaveLoadNamespace;
                    namespace ExtractionsNamespace
                    {//call ALL these methods with :
                    //using ExtractionsNamespace;
                    //Extractions ex = new Extractions();
                    public class ExtractionsClass
                    {
                    SaveLoadClass slc = new SaveLoadClass();

                        //STRING MANIPULATION !!!
                    
                    
                    
                    
                        public string tampon;
                        #region <\_\_\_\_\_ AddControl \_\_\_\_\_>
                        //if (checkBox1.Checked) tampon = "checkBox = true" + "\\r\\n";
                        //    else tampon = "checkBox = false" + "\\r\\n";
                        //tampon += "comboBox = " + comboBox1.Text + "\\r\\n";
                        //tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n";
                        //tampon += "progressBar = " + progressBar1.Value + "\\r\\n";
                        #endregion >AddControl-END<
                        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        /// <summary>call with: ex.AddControl(checkBox1, checkBox1.Checked);</summary>
                        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        public void AddControl(Control c, bool checkToAdd)
                        {
                            if (checkToAdd)
                                tampon += c.Name + " = true" + "\\r\\n";
                            else tampon += c.Name + " = false" + "\\r\\n";
                        }
                        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        /// <summary>call with: ex.AddControl(comboBox1, comboBox1.Text);</summary>
                        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        public void AddControl(Control c, string textToAdd)
                        { 
                            tampon += c.Name + " = " + textToAdd + " \\r\\n";
                        }
                        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        /// <summary>call with: ex.AddControl(numericUpDown1, numericUpDown1.Value.ToString());</summary>
                        //~~~
                    
                    1 Reply Last reply
                    0
                    • _ _Q12_

                      I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey. How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions? Thanks Here is the code:

                      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 SaveLoadNamespace;
                      using WarningsNamespace;
                      using System.Text.RegularExpressions;

                      namespace test7
                      {
                      public partial class Form1 : Form
                      {
                      public Form1()
                      {
                      InitializeComponent();
                      }
                      SaveLoadClass slc = new SaveLoadClass();
                      WarningsClass wc = new WarningsClass();

                          string tampon;
                          private void buttonSave\_Click(object sender, EventArgs e)
                          {
                              if (checkBox1.Checked)
                              {
                                  tampon = "checkBox = true" + "\\r\\n";
                              }
                              else
                              {
                                  tampon = "checkBox = false" + "\\r\\n";
                              }
                      
                              tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\\r\\n"; ;
                              tampon += "comboBox = " + comboBox1.Text + "\\r\\n"; ;
                      
                              slc.file\_SaveFile(tampon); label2.Text = wc.w2;
                      
                          }
                      
                          string buffer, s = ""; int i, j = 0;
                          private void buttonLoad\_Click(object sender, EventArgs e)
                          {
                              //STRING MANIPULATION !!!
                              slc.file\_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
                      
                              #region <\_\_\_\_\_ NumericUpDown \_\_\_\_\_>
                              //NumericUpDown
                              if (buffer.Contains("numericUpDown"))//if that,then should goto there
                              {
                                  i = buffer.IndexOf("numericUpDown");
                                  s = buffer.Remove(0, i); //remove the Begining of string
                                  if (s.Contains("\\r\\n"))  //folowing operations remove the Ending part of the string
                                  {
                                      i = s.IndexOf("\\r\\n");
                                      j = s.Length - i;
                                      s = s.Remove(i, j);
                                  }
                                  if (s.Contains("="))
                                  {
                                      i = s.IndexOf("=") + 1;
                                      s = s.Remove(0, i).Trim();
                                  }
                      
                                  i = int.Parse(s);
                                  numericUpDown1.Value = i;
                              }
                              #endregion >NumericUpDown-END<
                      
                      _ Offline
                      _ Offline
                      _Q12_
                      wrote on last edited by
                      #10

                      I need a suggestion from you: I want to make a saving program that is for windows only (not for internet) and who can imitate the Forum(in general) type of writing a text , store and display. Like the one i am writing right now. With a list box to display some saved text from a file, a textbox under -to write and save into that file.And a comboBox that can sort all "posts". Basically this is the hard part, the rest are decorations. How do you recommend me to do: Make for every "post" a file (for 100 posts will be 100 files) and the sorting is based on those files-its more intuitive to program it this way for me in my stage. OR - the very hard part: (because i know only the basics in string manipulation)... Make a single file with all the text and sorted it out by manipulating a string who contain the entire file.(a string that can retain in itself 99999999999999 characters-its even possible?-i doubt it. OR Again a single file that can be sorted but with the help of another one that contain some [sortings by address] from that large one. Basically there will be 2 files one with keywords representing addresses and the text attached to them, and the second one with only the keywords address. But This is a little overwhelming for me to think about and i seek help from you, the guru of programming world. Please give me a good solution...and how to think it through(programmatically). Thank you.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups