•

Check out our Community Blogs

# BenasG

Member Since 24 Apr 2012
Offline Last Active Jun 07 2012 03:08 AM

### In Topic: Random Integer Except Some Numbers

06 May 2012 - 01:02 PM

you should look this http://msdn.microsof...y/2dx6wyd4.aspx
there is a good explanation at last example...there are exceptions (not try-catch) with numbers in that example...if you don't understand something about that code just ask

Okey, will look at this example.

you should look this http://msdn.microsof...y/2dx6wyd4.aspx
there is a good explanation at last example...there are exceptions (not try-catch) with numbers in that example...if you don't understand something about that code just ask

So, you think that for loop would solve my problem? For loop faster than do while?

This is my code. So if I would use for loop I think I get the same problem..
```sk1 = RandomNumber(1, 21);
btn1 = int.Parse(_labelArray[sk1].Text);
do
{
sk2 = RandomNumber(1, 21);
} while (sk2 == sk1);
btn2 = int.Parse(_labelArray[sk2].Text);
do
{
sk3 = RandomNumber(1, 21);
} while ((sk3 == sk1) || (sk3 == sk2));
btn3 = int.Parse(_labelArray[sk3].Text);
do
{
sk4 = RandomNumber(1, 21);
} while ((sk4 == sk1) || (sk4 == sk2) || (sk4 == sk3));
btn4 = int.Parse(_labelArray[sk4].Text);
do
{
sk5 = RandomNumber(1, 21);
} while ((sk5 == sk1) || (sk5 == sk2) || (sk5 == sk3) || (sk5 == sk4));
btn5 = int.Parse(_labelArray[sk5].Text);
do
{
sk6 = RandomNumber(1, 21);
} while ((sk6 == sk1) || (sk6 == sk2) || (sk6 == sk3) || (sk6 == sk4) || (sk6 == sk5));
btn6 = int.Parse(_labelArray[sk6].Text);
do
{
sk7 = RandomNumber(1, 21);
} while ((sk7 == sk1) || (sk7 == sk2) || (sk7 == sk3) || (sk7 == sk4) || (sk7 == sk5) || (sk7 == sk6));
btn7 = int.Parse(_labelArray[sk7].Text);
do
{
sk8 = RandomNumber(1, 21);
} while ((sk8 == sk1) || (sk8 == sk2) || (sk8 == sk3) || (sk8 == sk4) || (sk8 == sk5) || (sk8 == sk6) || (sk8 == sk7));
btn8 = int.Parse(_labelArray[sk8].Text);
do
{
sk9 = RandomNumber(1, 21);
} while ((sk9 == sk1) || (sk9 == sk2) || (sk9 == sk3) || (sk9 == sk4) || (sk9 == sk5) || (sk9 == sk6) || (sk9 == sk7) || (sk9 == sk8));
btn9 = int.Parse(_labelArray[sk9].Text);
do
{
sk10 = RandomNumber(1, 21);
} while ((sk10 == sk1) || (sk10 == sk2) || (sk10 == sk3) || (sk10 == sk4) || (sk10 == sk5) || (sk10 == sk6) || (sk10 == sk7) || (sk10 == sk8) || (sk10 == sk9));
btn10 = int.Parse(_labelArray[sk10].Text);
do
{
sk11 = RandomNumber(1, 21);
} while ((sk11== sk1) || (sk11 == sk2) || (sk11 == sk3) || (sk11 == sk4) || (sk11 == sk5) || (sk11 == sk6) || (sk11 == sk7) || (sk11 == sk8) || (sk11 == sk9) || (sk11 == sk10));
btn11 = int.Parse(_labelArray[sk11].Text);
do
{
sk12 = RandomNumber(1, 21);
} while ((sk12 == sk1) || (sk12 == sk2) || (sk12 == sk3) || (sk12 == sk4) || (sk12 == sk5) || (sk12 == sk6) || (sk12 == sk7) || (sk12 == sk8) || (sk12 == sk9) || (sk12 == sk10) || (sk12 == sk11));
btn12 = int.Parse(_labelArray[sk12].Text);
do
{
sk13 = RandomNumber(1, 21);
} while ((sk13 == sk1) || (sk13 == sk2) || (sk13 == sk3) || (sk13 == sk4) || (sk13 == sk5) || (sk13 == sk6) || (sk13 == sk7) || (sk13 == sk8) || (sk13 == sk9) || (sk13 == sk10) || (sk13 == sk11) || (sk13 == sk12));
btn13 = int.Parse(_labelArray[sk13].Text);
do
{
sk14 = RandomNumber(1, 21);
} while ((sk14 == sk1) || (sk14 == sk2) || (sk14 == sk3) || (sk14 == sk4) || (sk14 == sk5) || (sk14 == sk6) || (sk14 == sk7) || (sk14 == sk8) || (sk14 == sk9) || (sk14 == sk10) || (sk14 == sk11) || (sk14 == sk12) || (sk14 == sk13));
btn14 = int.Parse(_labelArray[sk14].Text);
do
{
sk15 = RandomNumber(1, 21);
} while ((sk15 == sk1) || (sk15 == sk2) || (sk15 == sk3) || (sk15 == sk4) || (sk15 == sk5) || (sk15 == sk6) || (sk15 == sk7) || (sk15 == sk8) || (sk15 == sk9) || (sk15 == sk10) || (sk15 == sk11) || (sk15 == sk12) || (sk15 == sk13) || (sk15 == sk14));
btn15 = int.Parse(_labelArray[sk15].Text);
do
{
sk16 = RandomNumber(1, 21);
} while ((sk16 == sk1) || (sk16 == sk2) || (sk16 == sk3) || (sk16 == sk4) || (sk16 == sk5) || (sk16 == sk6) || (sk16 == sk7) || (sk16 == sk8) || (sk16 == sk9) || (sk16 == sk10) || (sk16 == sk11) || (sk16 == sk12) || (sk16 == sk13) || (sk16 == sk14) || (sk16 == sk15));
btn16 = int.Parse(_labelArray[sk16].Text);
do
{
sk17 = RandomNumber(1, 21);
} while ((sk17 == sk1) || (sk17 == sk2) || (sk17 == sk3) || (sk17 == sk4) || (sk17 == sk5) || (sk17 == sk6) || (sk17 == sk7) || (sk17 == sk8) || (sk17 == sk9) || (sk17 == sk10) || (sk17 == sk11) || (sk17 == sk12) || (sk17 == sk13) || (sk17 == sk14) || (sk17 == sk15) || (sk17 == sk16));
btn17 = int.Parse(_labelArray[sk17].Text);
do
{
sk18 = RandomNumber(1, 21);
} while ((sk18 == sk1) || (sk18 == sk2) || (sk18 == sk3) || (sk18 == sk4) || (sk18 == sk5) || (sk18 == sk6) || (sk18 == sk7) || (sk18 == sk8) || (sk18 == sk9) || (sk18 == sk10) || (sk18 == sk11) || (sk18 == sk12) || (sk18 == sk13) || (sk18 == sk14) || (sk18 == sk15) || (sk18 == sk16) || (sk18 == sk17));
btn18 = int.Parse(_labelArray[sk18].Text);
do
{
sk19 = RandomNumber(1, 21);
} while ((sk19 == sk1) || (sk19 == sk2) || (sk19 == sk3) || (sk19 == sk4) || (sk19 == sk5) || (sk19 == sk6) || (sk19 == sk7) || (sk19 == sk8) || (sk19 == sk9) || (sk19 == sk10) || (sk19 == sk11) || (sk19 == sk12) || (sk19 == sk13) || (sk19 == sk14) || (sk19 == sk15) || (sk19 == sk16) || (sk19 == sk17) || (sk19 == sk18));
btn19 = int.Parse(_labelArray[sk19].Text);
do
{
sk20 = RandomNumber(1, 21);
} while ((sk20 == sk1) || (sk20 == sk2) || (sk20 == sk3) || (sk20 == sk4) || (sk20 == sk5) || (sk20 == sk6) || (sk20 == sk7) || (sk20 == sk8) || (sk20 == sk9) || (sk20 == sk10) || (sk20 == sk11) || (sk20 == sk12) || (sk20 == sk13) || (sk20 == sk14) || (sk20 == sk15) || (sk20 == sk16) || (sk20 == sk17) || (sk20 == sk18) || (sk20 == sk19));
btn20 = int.Parse(_labelArray[sk20].Text);
do
{
sk21 = RandomNumber(1, 21);
} while ((sk21 == sk1) || (sk21 == sk2) || (sk21 == sk3) || (sk21 == sk4) || (sk21 == sk5) || (sk21 == sk6) || (sk21 == sk7) || (sk21 == sk8) || (sk21 == sk9) || (sk21 == sk10) || (sk21 == sk11) || (sk21 == sk12) || (sk21 == sk13) || (sk21 == sk14) || (sk21 == sk15) || (sk21 == sk16) || (sk21 == sk17) || (sk21 == sk18) || (sk21 == sk19) || (sk21 == sk20));
btn21 = int.Parse(_labelArray[sk21].Text);
```

### In Topic: Random Integer Except Some Numbers

06 May 2012 - 12:37 PM

Missing semicolon after the while test?

It`s okey in my code, I just made mistake here. So problem is still the same.

### In Topic: On Class B Access Labels/buttons From Class Form1

06 May 2012 - 09:10 AM

Ok, can you do the things as follows...

• Declare an event in the game class (you can use the MethodInvoker delegate to define the event) like 'StartingSignup'. So this event will be fired when the game class instance will start signing up.
• In your Form1 class bind that event to an event handler. And in this event handler do your buttons disabling thing (as well as other things you want to perform)
So the code will be something like following...
```
public class game
{

private event MethodInvoker _startingSignup;

public MethodInvoker StartingSignUp { get { return _startingSignup; } set { _startingSignup = value; } }

public game()
{

}

public void signup()
{
// Writes code here

// When time to disable your button, fire the event
// This way you don't need to access buttons/labels of Form1 inside game class
if (StartingSignUp != null)
{
StartingSignUp();
}
// Writes code here
}
}

public partial class Form1 : Form
{
game gameclass = new game();
public Form1()
{
InitializeComponent();
gameclass.StartingSignUp += new MethodInvoker(OnStartingSignUpEventHandler);
}

private void button1_Click(object sender, EventArgs e)
{
gameclass.signup();
}

private void OnStartingSignUpEventHandler()
{
// you can do other tasks here while starting signup.
}
}
```

Note that I have not compiled the code. I just wanted to show you what I mean by the above two steps.

Another question, why are you instantiating Form1 inside Game class?

Thanks, bro!

I just thought, that with this instantiating I get access to form. I was wrong.

### In Topic: On Class B Access Labels/buttons From Class Form1

06 May 2012 - 08:31 AM

You can access labels/buttons in a class by declaring the access-modifier as public. But I don't think this is a good way. Can you explain your situation about why do you need to access other class's (Forms or UserControls) labels/buttons?

Okey, I will try to explain my situation.
This is my code:
main class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CsharpKursinis_BenasGircys
{
public partial class Form1 : Form
{
game gameclass = new game();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
gameclass.signup();
}
}
}
other class game:

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CsharpKursinis_BenasGircys
{
public class game
{
Form1 mainClass = new Form1();

public game()
{

}

public void signup()
{

}
}
}
So I click button1, then call method signup from game class. I want that, when I click button1, this button would be disabled and I want to do this through game class method signup.

### In Topic: Convert Array Of Labels To Int

29 April 2012 - 01:36 PM

But labels don't have either int or double?

Yes, I`m just converting numbers. For example I have label1 = "1.0" so I`m converting it to number 1.0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download