Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: IF Then Else Statement loop??
PostPosted: Mon Sep 18, 2017 3:13 am 

Joined: Wed Sep 13, 2017 10:20 pm
Posts: 4

Offline
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


 Profile  
 
 Post subject: Re: IF Then Else Statement loop??
PostPosted: Wed Nov 08, 2017 2:57 pm 

Joined: Mon Nov 06, 2017 11:19 am
Posts: 11

Offline
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/library/zakwfxx4(v=vs.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,


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: