Click here to Skip to main content
15,887,275 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Do you know why I'm not getting any results?

Where is the error, please?

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Money_Management
{
    public partial class FMain : Form
    {
        public FMain()
        {
            InitializeComponent();
        }

        private void Btn_money_management_Click(object sender, EventArgs e)
        {
            string SoldeDuCompte = 
                 Text_Solde_Du_Compte.Text.Trim().ToString();
            string PositionAchat = Text_Position_Achat.Text.Trim().ToString();
            string PositionVente = Text_Stop_Loss.Text.Trim().ToString();
            string StopLoss = Text_Position_Achat.Text.Trim().ToString();
            string Risk = Text_Risk.Text.Trim().ToString();
            if (!string.IsNullOrEmpty(SoldeDuCompte) && 
                !string.IsNullOrEmpty(PositionAchat) && 
                !string.IsNullOrEmpty(PositionVente) && 
                !string.IsNullOrEmpty(StopLoss) && 
                !string.IsNullOrEmpty(Risk))
            {
                double DoubleSoldeDuCompte;
                double DoublePositionAchat;
                double DoublePositionVente;
                double DoubleStopLoss;
                double DoubleRisk;
                if (Double.TryParse(SoldeDuCompte, out DoubleSoldeDuCompte) 
                && Double.TryParse(PositionAchat, 
                out DoublePositionAchat) && 
                Double.TryParse(PositionVente, out DoublePositionVente) 
                && Double.TryParse(StopLoss, out DoubleStopLoss) 
                && Double.TryParse(Risk, out DoubleRisk))
                {
                    Double slpercent = 
                    (DoubleStopLoss - DoublePositionAchat) / DoublePositionAchat;
                    Double risk = DoubleRisk / 100;
                    Double ratio = risk / slpercent;
                    Double DoubleTaillePosition = DoubleSoldeDuCompte * ratio;

                    Label_Taille_Position.Text = " " + 
                            DoubleTaillePosition.ToString("#,#0.00 $");
                }
            }
        }
    }
}
Posted
Updated 27-Oct-23 4:57am
v2
Comments
Dave Kreskowiak 26-Oct-23 17:18pm    
STOP calling .ToString() on stuff that's already a string!!!

Sorry, it's a pet peeve of mine.

Put a breakpoint in your button handler and debug your application. Click the button and step through the code. If the breakpoint isn't hit, and it's a debug build, you haven't hooked the event up to your event handler.
 
Share this answer
 
Most likely one of the calls to Double.TryParse is failing and so the code following the if statement does not get executed. So split that statement into separate calls and report any that fail. Do not just assume that what you think should happen will happen.
 
Share this answer
 

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