Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
Ok guys this is the code.
I need the ceiling function in calculations so that the text displayed does not exceed the space available in the textbox.
I have done this in VB.Net. I have no clue as to how to perform the same in C#. I’m NOT a programmer; this is a hobby for me if you be so kind as to lend a helping hand.
Thanks again.
Lukann
C#
private void GoButt_Click(object sender, RoutedEventArgs e)
{
    try
    {
        double VL = Convert.ToDouble(LO.Text);
        double VA = Convert.ToDouble(AO.Text);
        double VTS = Convert.ToDouble(VL * VA);
        //
        TSF.Text = VTS.ToString();
        TMS.Text = (VL * 12 / 16).ToString();
        TMT.Text = (VL * 2 / 10).ToString();
        TMSc.Text = (VL * 12 / 16 * 4).ToString();
        int idxGSL = GSL.SelectedIndex;
        int idxCSL = CSL.SelectedIndex;
        double tmp = (((idxCSL + 1) * VTS) / (32 + 4 * idxGSL));
        TGB.Text = String.Format("{0}",tmp);
        TGBS.Text = (VTS * 1.5 / 258).ToString();
    }
    catch(Exception)
    {
        //Do something meaningful here
    }
}
Posted
Updated 4-Mar-11 3:26am
v4
Comments
wizardzz 3-Mar-11 15:24pm    
What is VTS or CSL? You need to provide more information for me to help.
Sergey Alexandrovich Kryukov 3-Mar-11 15:45pm    
Who cares?
wizardzz 3-Mar-11 15:50pm    
I figured he had tried using Math.Ceiling(), yet was still having trouble, possibly due to variable values. I didn't realize he made to effort on his own and that his question was so simple.

Sorry about the double post, my browser froze. Deleted initial comment.
Sergey Alexandrovich Kryukov 3-Mar-11 21:56pm    
No trouble at all; and thanks for your note.
I did not notice any effort from OP except formula not using Ceiling. I don't understand how one can make an issue out of this.
--SA
Sergey Alexandrovich Kryukov 3-Mar-11 15:47pm    
Lukann, did your try just to search in help? You won't make any progress if you're not learning to find answers by yourself; even the best Answer's won't help you.
--SA

C#
TGB.Text = (Math.Ceiling(VTS / 32 * (CSL.SelectedIndex +1))).ToString();
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 3-Mar-11 15:45pm    
Sure, my 5.
--SA
Lukann 3-Mar-11 17:46pm    
double' does not contain a definition for 'ToSring' and no extension method 'ToSring' accepting a first argument of type 'double' could be found
AspDotNetDev 3-Mar-11 17:50pm    
That was a typo, which I have fixed. Did you compare the differences between your code and the code I posted? That you could not figure out the problem was a typo indicates you may not be trying as hard as you should be.
Henry Minute 3-Mar-11 17:52pm    
Oh yes it does. Look here http://msdn.microsoft.com/en-us/library/3hfd35ad%28v=VS.90%29.aspx
AspDotNetDev 3-Mar-11 18:17pm    
My code originally said "ToSring" rather than "ToString". That is why Lukann was confused. Silly bugger couldn't work out that was a typo.
I understand that programming is your hobby, but it does not mean that you shouldn't improve your skills. To start with I strongly suggest using better naming rules (prefixes for controls, meaningful variable names etc.).

C#
private void GoButt_Click(object sender, RoutedEventArgs e)
        {
            double VL = 0;
            double VA = 0;
            int idxGSL = GSL.SelectedIndex;
            int idxCSL = CSL.SelectedIndex;
            if (!Double.TryParse(LO.Text, out VL))
            {
                // Optionally display a parsing error (e.g. using MessageBox.Show)
                return;
            }
            if (!Double.TryParse(AO.Text, out VA))
            {
                // Optionally display a parsing error (e.g. using MessageBox.Show)
                return;
            }
            if (idxGSL == -1 || idxCSL == -1)
            {
                return;
            }
            double VTS = VL * VA;
            double tmp = (((idxCSL + 1) * VTS) / (32 + 4 * idxGSL));
            TSF.Text = VTS.ToString();
            TMS.Text = (VL * 12 / 16).ToString();
            TMT.Text = (VL * 2 / 10).ToString();
            TMSc.Text = (VL * 12 / 16 * 4).ToString();
            TGBS.Text = (VTS * 1.5 / 258).ToString();

            // Is this what you want to achieve?
            TGB.Text = Math.Ceiling(tmp).ToString();
        }
 
Share this answer
 
v2
Comments
Olivier Levrey 4-Mar-11 9:26am    
Voted 5.
Dima Popov 4-Mar-11 12:20pm    
Thanks!
Lukann 4-Mar-11 16:10pm    
Thank you verry much.
Dima Popov 5-Mar-11 1:50am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900