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

VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 10:55 AM EST
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("%", ""));
VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 10:08 AM EST
D Lng11 reputationPosted Jan 5, 2012, 10:22 AM EST
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
VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 10:24 AM EST
I did it myself the other day and it took me a while to realize what the problem was :)
D Lng11 reputationPosted Jan 5, 2012, 10:42 AM EST
Thanks
D Lng11 reputationPosted Jan 5, 2012, 11:05 AM EST
Oh, one last thing, what is the command for ( tbAvail.Text ) to update automatically without having to click a button? Is that doable?
VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 11:27 AM EST
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.