This is my code:
public static ListBox listBox1 = new ListBox();
Form2.Globals.listBox1.Items.Add(Form2.Globals.din);
Form2.Globals.listBox1.Items.Add(Form2.Globals.dequi);
Form2.Globals.listBox1.Items.Add(Form2.Globals.demer);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debai);
Form2.Globals.listBox1.Items.Add(Form2.Globals.deval);
Form2.Globals.listBox1.Items.Add(Form2.Globals.denin);
Form2.Globals.listBox1.Items.Add(Form2.Globals.degoo);
Form2.Globals.listBox1.Items.Add(Form2.Globals.dehub);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debqui);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debmer);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debbai);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debval);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debnin);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debgoo);
Form2.Globals.listBox1.Items.Add(Form2.Globals.debhub);
StreamWriter save = new StreamWriter(savegame);
{
for (int i = 0; i < Form2.Globals.listBox1.Items.Count; i++)
{
save.WriteLine(Form2.Globals.listBox1.Items[i].ToString());
}
save.Dispose();
save.Close();
}
var din2 = Globals.listBox1.Items[0]; // <- line error
Globals.din = Convert.ToDouble(din2);
Error:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll
Additional information: InvalidArgument = Value '0' is not a value valid for 'index'.