0

I am storing values like this, but I want to store these values using array and want to load these values when I open program.

private void Button1_Click(object sender, EventArgs e)
{
    Properties.Settings.Default.VibratorValue1 = vibrator_numericUpDown1.Text;
    Properties.Settings.Default.VibratorValue2 = vibrator_numericUpDown2.Text;
    Properties.Settings.Default.VibratorValue3 = vibrator_numericUpDown3.Text;
    Properties.Settings.Default.VibratorValue4 = vibrator_numericUpDown4.Text;

    Properties.Settings.Default.Save();
}

private void Panel1_load(object sender, PaintEventArgs e)
{
    vib_numericUpDown1.Text = Properties.Settings.Default.VibValue1;
    vib_numericUpDown2.Text = Properties.Settings.Default.VibValue2;
    vib_numericUpDown3.Text = Properties.Settings.Default.VibValue3;
    vib_numericUpDown4.Text = Properties.Settings.Default.VibValue4;
}
janw
  • 8,758
  • 11
  • 40
  • 62
vathsa b
  • 1
  • 1
  • Does this answer your question? [Store String Array with Values in Application Settings](https://stackoverflow.com/questions/20130448/store-string-array-with-values-in-application-settings) – janw Mar 03 '20 at 11:08
  • I tried, it's not working. Getting error while loading .text values – vathsa b Mar 03 '20 at 11:17
  • Does it just "not work", or are there exceptions, broken or partial outputs, etc.? Following the steps in the selected answer works for me. – janw Mar 03 '20 at 11:21
  • An exception of type 'System.NullReferenceException' occurred in Experiment.exe but was not handled in user code – vathsa b Mar 03 '20 at 11:26
  • You need to initialize the array once (put default values in there using the settings designer). – janw Mar 03 '20 at 11:29
  • can we do this in multi-dimensional array? – vathsa b Mar 03 '20 at 11:29
  • Not directly; you'll have to write code that serializes your data into a format (e.g. JSON) that can be stored using one of the supported setting data types. – janw Mar 03 '20 at 11:30
  • yes, worked. How can i store values in Multi-dimension array? – vathsa b Mar 03 '20 at 11:32

0 Answers0