Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-04-28 22:43:09, last edited by goeyfun (2015-04-28 22:46:18)

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

Handling with check box

I have a bunch of check box to toggle admin commands
I wanna know is there a more systematic way to handle these check boxes //forums.everybodyedits.com/img/smilies/smile
this is my code structure

enum AdminCmds{edit,kick,load,clear};
bool admincmds //declaration[10]
if admincmds[(int)AdminCmds.edit]... //check if admin command is true or not

when checkbox_clicked event is raised

if(checkbox1.checked)admincmds[(int)AdminCmds.edit]=true;

Thanks


Ug3JzgO.png

Offline

#2 2015-04-28 23:03:09

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Handling with check box

Don't think so, and I don't see why this would be systematic enough for somebody.

Offline

#3 2015-04-28 23:09:14

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

Re: Handling with check box

your way of doing it?


Ug3JzgO.png

Offline

#4 2015-04-28 23:29:34

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Handling with check box

Just the way you use with the enum with the array I wouldn't think of myself and got me thinking for a sec, but it's actually a rather neat and readable way. Don't need the (int) in front though.

Offline

#5 2015-04-29 12:00:09

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: Handling with check box

You could use an array, probably?

int amount = 4; // Amount of check boxes.
bool[] checkBoxes = new bool[amount];
// 0 for edit, 1 for kick, 2 for load and 3 for clear.
// Get the edit checkbox state.
bool edit = checkBoxes[0];

You don't really need an enum.

Offline

#6 2015-04-29 13:22:49

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Handling with check box

DarkDragon4900 wrote:

You could use an array, probably?

int amount = 4; // Amount of check boxes.
bool[] checkBoxes = new bool[amount];
// 0 for edit, 1 for kick, 2 for load and 3 for clear.
// Get the edit checkbox state.
bool edit = checkBoxes[0];

You don't really need an enum.

admincmds is supposed to be an array (correct me if I'm wrong).
The enum is used for readability of which slot of the array indicates which command, which I find a rather good solution. Kudos/woot/etc. for that one btw.

Offline

#7 2015-04-29 14:55:20, last edited by DarkDragon4900 (2015-04-29 15:00:02)

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: Handling with check box

den3107 wrote:
DarkDragon4900 wrote:

You could use an array, probably?

int amount = 4; // Amount of check boxes.
bool[] checkBoxes = new bool[amount];
// 0 for edit, 1 for kick, 2 for load and 3 for clear.
// Get the edit checkbox state.
bool edit = checkBoxes[0];

You don't really need an enum.

admincmds is supposed to be an array (correct me if I'm wrong).
The enum is used for readability of which slot of the array indicates which command, which I find a rather good solution. Kudos/woot/etc. for that one btw.

I do know what an enum is. :p
Though, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

[EDIT] P.S. Dictionaries can serve the same purpose — pairing a string with each checkbox, with the string naming the checkbox type.
EE Messages use strings. ("say", "pt", "b", etc.) rather than enums (MessageType.Say).

Offline

#8 2015-04-29 15:15:49

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Handling with check box

DarkDragon4900 wrote:
den3107 wrote:
DarkDragon4900 wrote:

You could use an array, probably?

int amount = 4; // Amount of check boxes.
bool[] checkBoxes = new bool[amount];
// 0 for edit, 1 for kick, 2 for load and 3 for clear.
// Get the edit checkbox state.
bool edit = checkBoxes[0];

You don't really need an enum.

admincmds is supposed to be an array (correct me if I'm wrong).
The enum is used for readability of which slot of the array indicates which command, which I find a rather good solution. Kudos/woot/etc. for that one btw.

I do know what an enum is. //forums.everybodyedits.com/img/smilies/tongue
Though, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

[EDIT] P.S. Dictionaries can serve the same purpose — pairing a string with each checkbox, with the string naming the checkbox type.
EE Messages use strings. ("say", "pt", "b", etc.) rather than enums (MessageType.Say).

Using a Dictionary is slower and takes up a lot more RAM though. Obviously in this context you'd never notice the difference, but when talking big (this would include EE) the enum method would be better.

P.S. Yes, I'm saying that EE could be programmed better in some spots, for example by using enums instead of strings (also makes the size of the packets smaller and the servers faster).

P.P.S. I also admit that I probably wouldn't used the same way as EE because I wouldn't think of the enum method.

Offline

#9 2015-04-29 15:23:03

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: Handling with check box

Welp, the way he's using is fine enough.
And

DarkDragon4900 wrote:

Though, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

Though it is unnecessary, it isn't different in any way.
Since the values of enums are ints, anyway.
So stick with the way you're using.

Offline

#10 2015-04-29 15:46:22, last edited by goeyfun (2015-04-29 15:47:28)

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

Re: Handling with check box

DarkDragon4900 wrote:

hough, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

That's the reason i used enum...
Thx anyway //forums.everybodyedits.com/img/smilies/big_smile


Ug3JzgO.png

Offline

#11 2015-04-29 15:56:59

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Handling with check box

DarkDragon4900 wrote:

Welp, the way he's using is fine enough.
And

DarkDragon4900 wrote:

Though, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

Though it is unnecessary, it isn't different in any way.
Since the values of enums are ints, anyway.
So stick with the way you're using.

No, no, using your array thingy was fine, yes.
I was just making an objection to your edit there really.

Offline

#12 2015-04-30 11:05:46

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: Handling with check box

den3107 wrote:
DarkDragon4900 wrote:

Welp, the way he's using is fine enough.
And

DarkDragon4900 wrote:

Though, I was saying it's rather unnecessary to use an enum as an index for an array unless you're having trouble remembering which index is for which checkbox.

Though it is unnecessary, it isn't different in any way.
Since the values of enums are ints, anyway.
So stick with the way you're using.

No, no, using your array thingy was fine, yes.
I was just making an objection to your edit there really.

I can tell :p

Offline

#13 2015-04-30 14:21:30

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: Handling with check box

you can loop through controls :

foreach( Control c in Controls)
{
        if(c is CheckBox)
        {
                  //do something
        }
}

if you can read this....good for you

Offline

ewoke1430400090500134

Board footer

Powered by FluxBB

[ Started around 1714220072.4361 - Generated in 0.044 seconds, 12 queries executed - Memory usage: 1.56 MiB (Peak: 1.73 MiB) ]