IF Then Else Statement loop??
Posted: Mon Sep 18, 2017 3:13 am
Hey Guys,
I'm making a program where a user has 3 rows of 6 text boxes for saw positioning, they can click on each box and a pop up window appears where they can select 10 sizes to choose from to put into each of the boxes individually.
currently I have them click the box they want to change and assign a variable depending on the box they touched. if this variable = 1 (box 1 selected) it shows the popup and they select their size for the box. At the moment for each button i have to do an if variable number = x then take this value and put it into that box as below.
public partial class SizeTable_BoardSel_PU
{
void BTNBoard1_Click(System.Object sender, System.EventArgs e)
{
if (CutSizeBox.Selected ==1)
{
Globals.Tags.SizeTableCUT1_B1.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
else if (CutSizeBox.Selected ==2)
{
Globals.Tags.SizeTableCUT1_B2.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
else if (CutSizeBox.Selected ==3)
{
Globals.Tags.SizeTableCUT1_B3.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
is there some kind of loop i could use instead of writing CutSizeBox.Selected ==1 to ==18 for each box for each button?
Im pretty new to C# ie this afternoon was my first look at it so pretty happy I have got it working but feel there must be a way of truncating it a bit...
Any thoughts would be great
Cheers
I'm making a program where a user has 3 rows of 6 text boxes for saw positioning, they can click on each box and a pop up window appears where they can select 10 sizes to choose from to put into each of the boxes individually.
currently I have them click the box they want to change and assign a variable depending on the box they touched. if this variable = 1 (box 1 selected) it shows the popup and they select their size for the box. At the moment for each button i have to do an if variable number = x then take this value and put it into that box as below.
public partial class SizeTable_BoardSel_PU
{
void BTNBoard1_Click(System.Object sender, System.EventArgs e)
{
if (CutSizeBox.Selected ==1)
{
Globals.Tags.SizeTableCUT1_B1.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
else if (CutSizeBox.Selected ==2)
{
Globals.Tags.SizeTableCUT1_B2.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
else if (CutSizeBox.Selected ==3)
{
Globals.Tags.SizeTableCUT1_B3.Value = Globals.Tags.SizeTableBoardSize1.Value;
Globals.SizeTable_BoardSel_PU.Close();
}
is there some kind of loop i could use instead of writing CutSizeBox.Selected ==1 to ==18 for each box for each button?
Im pretty new to C# ie this afternoon was my first look at it so pretty happy I have got it working but feel there must be a way of truncating it a bit...
Any thoughts would be great
Cheers