Hi,
I have pasted some code below for two button actions to perform a calculation, the first button action causes the app to exit in the emulator, the second button action works good.
Any ideas please?
Thank you.
Code:
namespace WindowsPhoneApplication11
{
public partial class PanoramaPage1 : PhoneApplicationPage
{
public PanoramaPage1()
{
InitializeComponent();
}
// This button action crashes the app
private void btnGetAvail_Click(object sender, RoutedEventArgs e)
{
var compdown = Convert.ToDouble(tbundown) - Convert.ToDouble(tbplandown);
var shiftact = Convert.ToDouble(tbshift);
var not = shiftact - compdown;
var avail = not / shiftact * 100;
var availr = Math.Round(avail,2);
tbAvail.Text = availr + "%";
}
// This button action works good.
private void btnGetOEE_Click(object sender, RoutedEventArgs e)
{
//var total = Convert.ToDouble(tbYield.Text) * Convert.ToDouble(tbAvailability.Text) * Convert.ToDouble(tbPerformance.Text)* 100;
var total = Convert.ToDouble(tbYield.Text) * Convert.ToDouble(tbAvailability.Text) * Convert.ToDouble(tbPerformance.Text)* 100;
var rounded = Math.Round(total,2);
tbOEE.Text = rounded + "%";
}
}
}
Loading
VulpesPosted Jan 5, 2012, 3:55 PM
However, as it's already displayed in tbAvail, you could just remove the "%" from the end and parse it back to a double for the next calculation:
var availr = Convert.ToDouble(tbAvail.Text.Replace("%", ""));
VulpesPosted Jan 5, 2012, 4:27 PM
You could then handle the TextChanged events for the three other textboxes on which it depends: tbundown, tbplandown and tbshift.
Each time the text changes in these textboxes, you could then call the method to update tbAvail.
However, possible problems here include invalid input and whether the phone would be able to respond quickly enough as it would need to update on each key press.
D LngPosted Jan 5, 2012, 4:05 PM
Oh, one last thing, what is the command for ( tbAvail.Text ) to update automatically without having to click a button? Is that doable?
D LngPosted Jan 5, 2012, 3:42 PM
Thanks
VulpesPosted Jan 5, 2012, 3:24 PM
I did it myself the other day and it took me a while to realize what the problem was :)
D LngPosted Jan 5, 2012, 3:22 PM
Excuse my novice skills, I have just started learning this , less than 2 days, so sometimes cannot see the obvious stuff.
Thanks again.
I may be back with another problem soon . :P
VulpesPosted Jan 5, 2012, 3:08 PM