|
-
September 5th, 2010, 04:02 PM
#1
I need help with returning my list in one method to my labels in another method.
Hi,
I'm confused on how to return more then one item to my list to more then one label at the same time. Meaning i know how to return on 1 item from the list to 1 label but how do i return more then one item from the list to more then one label. for example on my code i for one item left on my list i use this code:
case 1:
firstlist[0] = firstlist[0] + 1;
return firstlist[0] = Int32.Parse(label1.Text);
but how would i use it for more then one item on list to equal to more then one label. exp.
list item index 0 = label1
list item index 1 = label2
list item index 2 = label3
I was thinking of using a while statement but how would i go and pick off each item of the list to send to the labels. Any help given would be great. thanks..
Here is my current Code: Its not complete but it includes both of the section that i'm working on..
private void button1_Click(object sender, EventArgs e)
{
Random Myrandom = new Random();
List<int> myInts = new List<int>();
label1.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
label2.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
label3.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
label4.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
label5.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
label6.Text = RandomNumber(1, 53, Myrandom, myInts).ToString();
}
private int RandomNumber(int min, int max, Random mynumb, List<int> LottNum)
{
int nRN = 0;
// Start the for loop
for (int i = 1; i > 0; i++)
{
string numTxt01,
numTxt02,
numTxt03,
numTxt04,
numTxt05,
numTxt06;
int numTxt1,
numTxt2,
numTxt3,
numTxt4,
numTxt5,
numTxt6,
total;
// Convert the first number to numeric
numTxt01 = textBox1.Text;
numTxt1 = Int32.Parse(numTxt01);
// Convert the second number to numeric
numTxt02 = textBox2.Text;
numTxt2 = Int32.Parse(numTxt02);
// Convert the third number to numeric
numTxt03 = textBox3.Text;
numTxt3 = Int32.Parse(numTxt03);
//Convert the fourth number to numeric
numTxt04 = textBox4.Text;
numTxt4 = Int32.Parse(numTxt04);
// Convert the fifth number to numeric
numTxt05 = textBox5.Text;
numTxt5 = Int32.Parse(numTxt05);
//Convert the sixth number to numeric
numTxt06 = textBox6.Text;
numTxt6 = Int32.Parse(numTxt06);
List<int> firstlist = new List<int>();
Random listRand = new Random();
//We add these number from the textbox to a list
firstlist.Add(numTxt1);
firstlist.Add(numTxt2);
firstlist.Add(numTxt3);
firstlist.Add(numTxt4);
firstlist.Add(numTxt5);
firstlist.Add(numTxt6);
int numberOfElementsToRemove = listRand.Next(3, 5);
while (numberOfElementsToRemove > 0)
{
firstlist.RemoveAt(listRand.Next(firstlist.Count() - 1));
numberOfElementsToRemove--;
}
int numberpicked = 0;
if (firstlist.Count == 1)
numberpicked = listRand.Next(1, 3);
else if
(firstlist.Count == 2)
numberpicked = listRand.Next(4, 7);
else if
(firstlist.Count == 3)
numberpicked = listRand.Next(8, 11);
switch (numberpicked)
{
case 1:
firstlist[0] = firstlist[0] + 1;
return firstlist[0] = Int32.Parse(label1.Text);
case 2:
firstlist[0] = firstlist[0] - 1;
return firstlist[0] = Int32.Parse(label1.Text);
case 3:
firstlist[0] = firstlist[0];
return firstlist[0] = Int32.Parse(label1.Text);
case 4:
// Add one
firstlist[0] = firstlist[0] + 1;
firstlist[1] = firstlist[1] - 1;
return firstlist[0] = Int32.Parse(label1.Text);
case 5:
// Add one
firstlist[0] = firstlist[0] - 1;
firstlist[1] = firstlist[1] + 1;
return firstlist[0] = Int32.Parse(label1.Text)
case 6:
// Add one
firstlist[0] = firstlist[0] - 1;
firstlist[1] = firstlist[1];
break;
case 7:
// Add one
firstlist[0] = firstlist[0] + 1;
firstlist[1] = firstlist[1];
break;
case 8:
// Add one
firstlist[0] = firstlist[0] + 1;
firstlist[1] = firstlist[1] - 1;
firstlist[2] = firstlist[2];
break;
case 9:
// Subtract one
firstlist[0] = firstlist[0] - 1;
firstlist[1] = firstlist[1] + 1;
firstlist[2] = firstlist[2];
break;
case 10:
// Leave as is
firstlist[0] = firstlist[0];
firstlist[1] = firstlist[1];
firstlist[2] = firstlist[2] - 1;
break;
case 11:
firstlist[0] = firstlist[0];
firstlist[1] = firstlist[1];
firstlist[2] = firstlist[2] + 1;
break;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|