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
IF Then Else Statement loop??
-
- Posts: 13
- Joined: Mon Nov 06, 2017 11:19 am
Re: IF Then Else Statement loop??
The use of a loop is used for cycling through a block of code while a condition is being met e.g. increment a variable/object. If you wanted to use a loop, you would still have to define each condition of the options. You can however write your IF statements differently using Ternary Operators. Check out this link to learn more about it.
https://msdn.microsoft.com/en-us/librar ... s.90).aspx
If I didn't answer your question, please feel free to contact Beijer Support and we can get more details and walk through this together.
Thanks,
https://msdn.microsoft.com/en-us/librar ... s.90).aspx
If I didn't answer your question, please feel free to contact Beijer Support and we can get more details and walk through this together.
Thanks,