Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
Questioncrystal report visual studio 2010 Pin
kalaiselvansurya21-Apr-13 4:17
kalaiselvansurya21-Apr-13 4:17 
QuestionWPF: Add child node to TreeView for other thread Pin
Boltian21-Apr-13 1:41
Boltian21-Apr-13 1:41 
AnswerRe: WPF: Add child node to TreeView for other thread Pin
Dave Kreskowiak21-Apr-13 4:14
mveDave Kreskowiak21-Apr-13 4:14 
GeneralRe: WPF: Add child node to TreeView for other thread Pin
Boltian6-May-13 6:43
Boltian6-May-13 6:43 
GeneralRe: WPF: Add child node to TreeView for other thread Pin
Dave Kreskowiak6-May-13 7:34
mveDave Kreskowiak6-May-13 7:34 
Questionerro ao fazer um calculo deixando o campo desconto vazio! Pin
Member 1000184520-Apr-13 17:55
Member 1000184520-Apr-13 17:55 
AnswerRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
PIEBALDconsult20-Apr-13 18:04
mvePIEBALDconsult20-Apr-13 18:04 
AnswerRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
OriginalGriff20-Apr-13 21:58
mveOriginalGriff20-Apr-13 21:58 
I'm not going to try and respond in Portugese: So you may want to find Translate.Google.com[^] to help you in future...

Why are you using two different methods to convert strings to doubles? Particularly when you are converting user input values from text boxes, you should always allow for input errors, and use double.TryParse as in your final example. However, when you use any of the TryParse methods, you must check the return value, or it is a waste of time. You have some error checking on the first three values, but why not check them with TryParse as well? At the moment if there is a problem with any of the first three fields, you do nothing - which is what you are complaining about...
Try this:
C#
private void calcula()
    {
    double valorUnitario, quantidade, desconto, valorPago, troco, total;
    if (!double.TryParse(txtValorUnitario.Text, out valorUnitario))
        {
        ... Report problem to user
        return;
        }
    if (!double.TryParse(txtQuantidade.Text, out quantidade))
        {
        ... Report problem to user
        return;
        }
    if (!double.TryParse(txtValorPago.Text, out valorPago))
        {
        ... Report problem to user
        return;
        }
    if (!double.TryParse(txtDesconto.Text, out desconto))
        {
        ... Report problem to user
        return;
        }

    total = (valorUnitario * quantidade) - desconto;
    troco = valorPago - total;

    txtValorTotal.Text = String.Format("{0:C}", total);
    txtTroco.Text = String.Format("{0:C", troco);
    txtTotal.Text = String.Format("{0:C", total);
    }

The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
Member 1000184524-Apr-13 13:03
Member 1000184524-Apr-13 13:03 
GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
OriginalGriff24-Apr-13 21:52
mveOriginalGriff24-Apr-13 21:52 
GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
Member 1000184524-Apr-13 23:42
Member 1000184524-Apr-13 23:42 
GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
OriginalGriff25-Apr-13 0:19
mveOriginalGriff25-Apr-13 0:19 
GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
Member 1000184526-Apr-13 11:58
Member 1000184526-Apr-13 11:58 
GeneralRe: erro ao fazer um calculo deixando o campo desconto vazio! Pin
OriginalGriff26-Apr-13 21:39
mveOriginalGriff26-Apr-13 21:39 
QuestionIs monodevelo suitable for a digital pet project in linux? Pin
eleazaro20-Apr-13 10:26
eleazaro20-Apr-13 10:26 
AnswerRe: Is monodevelo suitable for a digital pet project in linux? Pin
jschell21-Apr-13 6:02
jschell21-Apr-13 6:02 
AnswerRe: Is monodevelo suitable for a digital pet project in linux? Pin
Eddy Vluggen21-Apr-13 9:06
professionalEddy Vluggen21-Apr-13 9:06 
Questionexample for using webrequest and webresopnse Pin
arashmousapour20-Apr-13 2:37
arashmousapour20-Apr-13 2:37 
AnswerRe: example for using webrequest and webresopnse Pin
Mycroft Holmes20-Apr-13 13:56
professionalMycroft Holmes20-Apr-13 13:56 
QuestionDev platform for Kinect Pin
hanzibal219-Apr-13 23:18
hanzibal219-Apr-13 23:18 
QuestionVS C# Application Choice Pin
MWRivera19-Apr-13 12:13
MWRivera19-Apr-13 12:13 
AnswerRe: VS C# Application Choice Pin
NotPolitcallyCorrect19-Apr-13 14:10
NotPolitcallyCorrect19-Apr-13 14:10 
AnswerRe: VS C# Application Choice Pin
Yvan Rodrigues19-Apr-13 14:11
professionalYvan Rodrigues19-Apr-13 14:11 
AnswerRe: VS C# Application Choice Pin
Garth J Lancaster19-Apr-13 14:12
professionalGarth J Lancaster19-Apr-13 14:12 
AnswerRe: VS C# Application Choice Pin
Karthik Harve19-Apr-13 20:24
professionalKarthik Harve19-Apr-13 20:24 

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.