Click here to Skip to main content
15,881,757 members
Home / Discussions / C#
   

C#

 
GeneralRe: Constructor issue Pin
Jibesh11-Feb-13 6:38
professionalJibesh11-Feb-13 6:38 
AnswerRe: Constructor issue Pin
Shameel11-Feb-13 5:02
professionalShameel11-Feb-13 5:02 
Questionif loop cant excuted properly Pin
abhishek91111911-Feb-13 0:36
abhishek91111911-Feb-13 0:36 
AnswerRe: if loop cant excuted properly Pin
Pete O'Hanlon11-Feb-13 0:45
mvePete O'Hanlon11-Feb-13 0:45 
AnswerRe: if loop cant excuted properly Pin
Dave Kreskowiak11-Feb-13 2:09
mveDave Kreskowiak11-Feb-13 2:09 
AnswerRe: if loop cant excuted properly Pin
Bernhard Hiller11-Feb-13 2:27
Bernhard Hiller11-Feb-13 2:27 
GeneralRe: if loop cant excuted properly Pin
Simon_Whale11-Feb-13 3:58
Simon_Whale11-Feb-13 3:58 
AnswerRe: if loop cant excuted properly Pin
Jegan Thiyagesan11-Feb-13 6:27
Jegan Thiyagesan11-Feb-13 6:27 
C#
Hi
First, like others mentioned, "if" and "else" are conditional statements, they are not loop.
Second, the textbox will return empty if it has no value assigned to it, so checking for null is redundant.
Third, this is a coding horror!

if (txtdisc.Text ==null)  This check is redundant therefore  the calls below will never be executed.
{
   txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;

   Double txtdisc22013 = Convert.ToDouble(txtdisc.Text); Converting a null to a nullable Double will 0.0;

   txttot22013 = txttot22013 - txtdisc22013; (Some value0.0)

   txttot.Text = txttot22013.ToString();
}
else
{
   txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;

   txttot.Text = txttot22013.ToString(); The value of "txttot22013" in the else conditions  is no different to the one in if condition.
}

if (txtvat.Text == null)
{
   MessageBox.Show("Enter Vat Amount"); This will never be called.
}
else
{
   Double txtvat22013 = Convert.ToDouble(txtvat.Text); Possible exception.

   txtvat22013 = txtvat22013 / 100;

   txtvat22013 = txtvat22013 * txttot22013;

   Double txtvatinclu22013 = txtvat22013 + txttot22013;

   txtvatinclu.Text = txtvatinclu22013.ToString();
}


If I rewrite your code, it may as follows:

txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString();

if (string.IsNullOrEmpty(txtvat.Text))
{
    MessageBox.Show("Enter Vat Amount");
}
else
{
    double txtvat22013;
    if (Double.TryParse(txtvat.Text, txtvat22013))
    {
        Double txtvatinclu22013 = (txtvat22013 * txttot22013 / 100) + txttot22013;

        txtvatinclu.Text = txtvatinclu22013.ToString();
    }else
    {
    MessageBox.Show("Enter Valid Vat Amount");
    }
}

Regards
Jegan

GeneralRe: if loop cant excuted properly Pin
abhishek91111911-Feb-13 8:06
abhishek91111911-Feb-13 8:06 
GeneralRe: if loop cant excuted properly Pin
DanielSheets19-Feb-13 7:59
DanielSheets19-Feb-13 7:59 
QuestionInvoke schedule task using .NET program Pin
siddisagar11-Feb-13 0:30
siddisagar11-Feb-13 0:30 
AnswerRe: Invoke schedule task using .NET program Pin
Dave Kreskowiak11-Feb-13 2:12
mveDave Kreskowiak11-Feb-13 2:12 
GeneralRe: Invoke schedule task using .NET program Pin
siddisagar11-Feb-13 21:47
siddisagar11-Feb-13 21:47 
GeneralRe: Invoke schedule task using .NET program Pin
Dave Kreskowiak12-Feb-13 11:46
mveDave Kreskowiak12-Feb-13 11:46 
AnswerRe: Invoke schedule task using .NET program Pin
José Amílcar Casimiro11-Feb-13 3:35
José Amílcar Casimiro11-Feb-13 3:35 
Questionstoring images to folder in c# Pin
dhiraj3110-Feb-13 9:40
dhiraj3110-Feb-13 9:40 
AnswerRe: storing images to folder in c# Pin
Garth J Lancaster10-Feb-13 9:53
professionalGarth J Lancaster10-Feb-13 9:53 
Questionstoring images to folder in c# Pin
dhiraj3110-Feb-13 9:38
dhiraj3110-Feb-13 9:38 
AnswerMessage Closed Pin
10-Feb-13 9:58
professionalJibesh10-Feb-13 9:58 
GeneralRe: storing images to folder in c# Pin
Pete O'Hanlon10-Feb-13 10:07
mvePete O'Hanlon10-Feb-13 10:07 
QuestionHow to create a C# Application which can automatically install an Application or server ? Pin
Rahul Sarkar10-Feb-13 6:43
Rahul Sarkar10-Feb-13 6:43 
AnswerRe: How to create a C# Application which can automatically install an Application or server ? Pin
Rahul Sarkar10-Feb-13 6:58
Rahul Sarkar10-Feb-13 6:58 
AnswerRe: How to create a C# Application which can automatically install an Application or server ? Pin
Jegan Thiyagesan13-Feb-13 2:52
Jegan Thiyagesan13-Feb-13 2:52 
QuestionC# connection pooling Pin
classy_dog9-Feb-13 21:52
classy_dog9-Feb-13 21:52 
AnswerRe: C# connection pooling Pin
N a v a n e e t h10-Feb-13 3:19
N a v a n e e t h10-Feb-13 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.