Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am creating a windows application showing name date of birth and number of heartbeats from date of birth to a particular targetdate. My program is showing name and date of birth but i cannot get the program to work out the calculations. i have declared the variables at the top as beats per day and beats per week etc, i was wondering if anyone can help me as on how to get the program to calculate all these values once the enter button is pressed? here is my code, many thanks
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace q3
{
    public partial class Form1 : Form
    {
        int bpd;
        int bpw;
        int bpm;
        int bpy;
        int bted;
        int enb;
        public Form1()
        {
            InitializeComponent();
        }
        private void btnenter_Click(object sender, EventArgs e)
        {
            bpd = 70 * 23;
            bpw = 1680 * 5;
            bpm = 11760 * 6;
            bpy = 47040 * 13;
            bted = 564480 * 39;
            enb = 22456560 + 16800;

        }

        private void txtheartbeats_TextChanged(object sender, EventArgs e)
        {
            txtheartbeats.Text = "enb";
        }
        private void txtname_TextChanged(object sender, EventArgs e)
        {
            txtname.Text = "John Smith";
        }
        private void txtDob_TextChanged(object sender, EventArgs e)
        {
            txtDob.Text = "05/10/1990";
        }
        private void txtTargetdate_TextChanged(object sender, EventArgs e)
        {
            txtTargetdate.Text = "11/10/2020";
        }

    }
}
Posted
Updated 22-Apr-10 2:17am
v2

Store your DOB as a DateTime - you can then subtract it from your target DateTime to give a TimeSpan[^]. You can then use the various properties to give you the basic numbers you need.
 
Share this answer
 
Its simple mathematics; x = a + b
What are you having difficulties with?

Also, setting the text, such as txtheartbeats.Text = "enb"; is doing nothing. It cancels out anything that is entered in the textboxes. You might as week just use a label.
 
Share this answer
 
In which case (and in future, please modify your question rather than answering yourself) you need to handle the Button.Click event, rather than the textbox.TextChanged event. All you will do in your existing code is go round an round in a loop:
txtTargetdate_TextChanged event sets text of txtTargetdate -> causes txtTargetdate_TextChanged event, which sets the text of ....

Instead, set the textbox.Text values in a single myButton_Click event, and remove the TextChanged event handler from all text boxes.
 
Share this answer
 
all the values such as

bpd = 70 * 23; bpw = 1680 * 5; bpm = 11760 * 6; bpy = 47040 * 13; bted = 564480 * 39; enb = 22456560 + 16800;

have been caluclated by myself, I am trying to get the program to display these once the enter button has been clicked

thanks
 
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