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.
Pages: 1
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
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
Offline
Don't think so, and I don't see why this would be systematic enough for somebody.
Offline
Offline
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
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
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
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
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.
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
Welp, the way he's using is fine enough.
And
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
Offline
Welp, the way he's using is fine enough.
AndDarkDragon4900 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
DarkDragon4900 wrote:Welp, the way he's using is fine enough.
AndDarkDragon4900 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
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
Pages: 1
[ Started around 1732484731.2356 - Generated in 0.070 seconds, 14 queries executed - Memory usage: 1.56 MiB (Peak: 1.73 MiB) ]