2
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.Argued tofrangeexception' occurred in System.Windows.Forms.dll
Additional information: Invalidargument=Value '0' is not a value valid for 'index'.
This code is very complicated and does things that should not, but the problem is that the
Form2
beforeGlobals.listBox1.Items
on the error line. It’s just what I see differently that could cause the error.– Maniero