bind
IS-IT--Management
- Dec 13, 2004
- 25
Greetings!
I'm having a bit of trouble with my Non repeating random number generator, basically this function will grab a start and ending number and generate random numbers between the start and end point.
private void GetRandom(int start, int max)
{
start:
if (listBox1.Items.Count == max)
{
DialogResult dlgResult = MessageBox.Show("Error: all numbers contained in range have been used, reset list?", "Reset list?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{
listBox1.Items.Clear();
foreach (Control c in this.Controls)
if (c is TextBox)
(c as TextBox).Clear();
SaveList();
}
return;
}
Random rndNumber = new Random();
int number = rndNumber.Next(start, max + 1);
if (CheckList(listBox1, number) == false)
{
listBox1.Items.Add(number);
textBox3.Text = (number.ToString());
SaveList();
}
else
{
goto start;
}
}
If I save the contents of the listbox and close the program and reopen it, its almost as if listbox.items.contains just stops working entirely... not sure what the deal is.
here's my opening func:
String[] info;
string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\list.txt";
if (File.Exists(path))
{
info = File.ReadAllLines(path);
for (int i = 0; i < info.Length; i++)
{
listBox1.Items.Add(info);
}
}
else
{
File.Open(path, FileMode.Create).Close();
}
textBox1.Text = Properties.Settings.Default.start;
textBox2.Text = Properties.Settings.Default.end;
Question is this, is there some sort of internal memory the contains field works off of? is there any way to repopulate it's index?
I just dont know how else to go about this.
The app is supposed to basically keep track of previously generated numbers, saves the contents of the generated numbers in a listbox and writes to a text file on close, when the app is reopened and you click generate, shouldn't listbox.items.contains iterate through everything in the listbox to find the previously generated number?
Problem is, it's generating previously generated numbers and throwing them in the listbox, almost as if the listbox.items.contains is failing.
Any help on this will be appreciated!
Thank you!
I'm having a bit of trouble with my Non repeating random number generator, basically this function will grab a start and ending number and generate random numbers between the start and end point.
private void GetRandom(int start, int max)
{
start:
if (listBox1.Items.Count == max)
{
DialogResult dlgResult = MessageBox.Show("Error: all numbers contained in range have been used, reset list?", "Reset list?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{
listBox1.Items.Clear();
foreach (Control c in this.Controls)
if (c is TextBox)
(c as TextBox).Clear();
SaveList();
}
return;
}
Random rndNumber = new Random();
int number = rndNumber.Next(start, max + 1);
if (CheckList(listBox1, number) == false)
{
listBox1.Items.Add(number);
textBox3.Text = (number.ToString());
SaveList();
}
else
{
goto start;
}
}
If I save the contents of the listbox and close the program and reopen it, its almost as if listbox.items.contains just stops working entirely... not sure what the deal is.
here's my opening func:
String[] info;
string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\list.txt";
if (File.Exists(path))
{
info = File.ReadAllLines(path);
for (int i = 0; i < info.Length; i++)
{
listBox1.Items.Add(info);
}
}
else
{
File.Open(path, FileMode.Create).Close();
}
textBox1.Text = Properties.Settings.Default.start;
textBox2.Text = Properties.Settings.Default.end;
Question is this, is there some sort of internal memory the contains field works off of? is there any way to repopulate it's index?
I just dont know how else to go about this.
The app is supposed to basically keep track of previously generated numbers, saves the contents of the generated numbers in a listbox and writes to a text file on close, when the app is reopened and you click generate, shouldn't listbox.items.contains iterate through everything in the listbox to find the previously generated number?
Problem is, it's generating previously generated numbers and throwing them in the listbox, almost as if the listbox.items.contains is failing.
Any help on this will be appreciated!
Thank you!