timer1_Tick event problem

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 6619 Views - Last Post: 25 February 2011 - 07:23 PM Rate Topic: -----

#1 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

timer1_Tick event problem

Posted 21 February 2011 - 08:02 AM

I am trying to set up a timer to display text in a time period from 8 am to 8 pm in a Visual C# Windows form application. I have set the timer to be enabled at 8 am through 8 pm (i think) but I don't have my code correct. Here is my code. If there is anyone that can help with this it would be greatly appreciated.
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 TimeZone
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DateTime startDuration = DateTime.Today.AddHours(08);
        DateTime endDuration = DateTime.Today.AddHours(20);

        private void areaCodeDataBaseTableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.areaCodeDataBaseTableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.areaCodeDataBaseDataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'areaCodeDataBaseDataSet.AreaCodeDataBaseTable' table. You can move, or remove it, as needed.
            this.areaCodeDataBaseTableTableAdapter.Fill(this.areaCodeDataBaseDataSet.AreaCodeDataBaseTable);

        }

        private void DigitalClock_Load(object sender, EventArgs e)
        {
            Timer t = new Timer();
            t.Tick += new EventHandler(t_Tick);
            t.Interval = 1000;
            t.Enabled = true;
        }
        

        public void t_Tick(Object Sender, EventArgs e)
        {
            if (time_ZoneLabel1.Text == "Eastern")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(19).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Central")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Mountain")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Pacific")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(16).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Atlantic")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(20).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Hawaii-Aleutian")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(14).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Eastern/Central")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(19).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "Central/Mountain")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "Mountain/Pacific")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(16).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "UTC+10")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(10).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "UTC-10")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(20).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "")
            {
                DigitalClock.Text = "";
                DigitalClock2.Text = "";
            }
        }

        

        private void exitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (startDuration >= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            if (endDuration <= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
        }

        private void warningLabel1(object sender, EventArgs e)
        {
            if (timer1.Enabled)
            { 
                warningLabel.Text = "OK To Call";
            }
            else
            {
                warningLabel.Text = "Do Not Call";
            }
        }
}

}


This post has been edited by Enderz: 21 February 2011 - 08:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: timer1_Tick event problem

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: timer1_Tick event problem

Posted 21 February 2011 - 08:05 AM

What's wrong with the code? Are there errors during the build? And if so, post those errors here. If there are no errors, what is happening that you do not expect?
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: timer1_Tick event problem

Posted 21 February 2011 - 08:10 AM

This about this logic...

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (startDuration >= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            if (endDuration <= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
        }



If the current time is 11PM at night, then it successfully passes the first IF statement. However, this isn't what you want to happen.

You should combine the two IF statements that enable the timer.

Also, this is horrible. You are creating a new timer every time. Why?
Was This Post Helpful? 0
  • +
  • -

#4 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 21 February 2011 - 08:10 AM

View PostKilorn, on 21 February 2011 - 08:05 AM, said:

What's wrong with the code? Are there errors during the build? And if so, post those errors here. If there are no errors, what is happening that you do not expect?

No there are no errors when I run the program the Text just isn't displayed in the Label.
Was This Post Helpful? 0
  • +
  • -

#5 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 21 February 2011 - 08:17 AM

View Posteclipsed4utoo, on 21 February 2011 - 08:10 AM, said:

This about this logic...

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (startDuration >= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            if (endDuration <= DateTime.Now)
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
        }



If the current time is 11PM at night, then it successfully passes the first IF statement. However, this isn't what you want to happen.

You should combine the two IF statements that enable the timer.

Also, this is horrible. You are creating a new timer every time. Why?

Ok I tried to add the if statements but it still doesn't work correctly but maybe I misunderstood.
And I created a new timer because I thought needed one for this if this is incorrect could you explain how I can fix this.
I am new to Visual C# and have been learning on my own. here is what I did to combine the if statements.

        private void timer1_Tick(object sender, EventArgs e)
        {

            if ((startDuration >= DateTime.Now)&&(endDuration <= DateTime.Now))
            {
                Timer timer1 = new Timer();
                timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
            
            else
            {
                timer1.Enabled = false;
            }
        }


Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5441
  • View blog
  • Posts: 11,676
  • Joined: 02-June 10

Re: timer1_Tick event problem

Posted 21 February 2011 - 08:18 AM

I think you've made it more complicated than you need to.
There is no need for a startduration datetime object or an endduration

Try this logic:

Timer ticks every 1 second.
tick_handler
if DateTime.Now.Hours > 7 and < 20
{
// Display and do stuff
}
else
{
// clear the lable and do other stuff
}
Was This Post Helpful? 2
  • +
  • -

#7 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: timer1_Tick event problem

Posted 21 February 2011 - 10:16 AM

This should help you out .

Ask if this is not what you want

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
    

        DateTime start = DateTime.Parse("08:00 am");
        DateTime end = DateTime.Parse("08:00 pm").AddHours(10);

        private void Form1_Load(object sender, EventArgs e)
        {

            if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start && DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end)
            {

                //Do Logic here
                timer.Enabled = true;
                timer.Start();
                timer.Interval = 1000;
                timer.Tick += new EventHandler(timer_Tick);
               
            }
            else
            {

                //Do logic here
            }
        }



        public void timer_Tick(Object Sender, EventArgs e)
        {

            //Do logic here 
            label1.Text = DateTime.Now.ToString();
            Form1_Load(Sender, e);
        }
    }
}

Was This Post Helpful? 0
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: timer1_Tick event problem

Posted 21 February 2011 - 10:21 AM

View Postmarinus, on 21 February 2011 - 01:16 PM, said:

This should help you out .

Ask if this is not what you want

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
    

        DateTime start = DateTime.Parse("08:00 am");
        DateTime end = DateTime.Parse("08:00 pm").AddHours(10);

        private void Form1_Load(object sender, EventArgs e)
        {

            if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start && DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end)
            {

                //Do Logic here
                timer.Enabled = true;
                timer.Start();
                timer.Interval = 1000;
                timer.Tick += new EventHandler(timer_Tick);
               
            }
            else
            {

                //Do logic here
            }
        }



        public void timer_Tick(Object Sender, EventArgs e)
        {

            //Do logic here 
            label1.Text = DateTime.Now.ToString();
            Form1_Load(Sender, e);
        }
    }
}


That actually doesn't help out at all. That would mean the user would have to close and open the application for it to determine if the timer should be enabled.

I am going to go with tlhIn`toq on this one. Also, you don't need two timers. You already have one timer, do the check there.

Also, those IF statements should probably a switch statement instead, assuming you can't have multiple timezones selected.
Was This Post Helpful? 1
  • +
  • -

#9 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5441
  • View blog
  • Posts: 11,676
  • Joined: 02-June 10

Re: timer1_Tick event problem

Posted 21 February 2011 - 10:34 AM

You do know you don't have to re-invent the wheel to get the timezone, right?
You can just ask for it from the .NET Timezone class.
http://msdn.microsof...m.timezone.aspx


DateTime start = DateTime.Parse("08:00 am");
        DateTime end = DateTime.Parse("08:00 pm").AddHours(10);


You do realize that a DateTime object includes the DATE component, right?
So when you set this for 8am & 8pm TODAY, it does you no good when you run the application overnight and it becomes TOMORROW. Your start & end object are still set for what has now become YESTERDAY.
Was This Post Helpful? 2
  • +
  • -

#10 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 21 February 2011 - 11:20 AM

View PosttlhIn`toq, on 21 February 2011 - 08:18 AM, said:

I think you've made it more complicated than you need to.
There is no need for a startduration datetime object or an endduration

Try this logic:

Timer ticks every 1 second.
tick_handler
if DateTime.Now.Hours > 7 and < 20
{
// Display and do stuff
}
else
{
// clear the lable and do other stuff
}

Thanks a lot I am now on the right track
Was This Post Helpful? 0
  • +
  • -

#11 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 21 February 2011 - 11:37 AM

Ok Thank you all for the help I got it working correctly now.
Was This Post Helpful? 0
  • +
  • -

#12 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 22 February 2011 - 03:49 PM

I thought this was going to work but I still have a problem that I didn't notice at first on the application, the above information helped but the application still pulls the computers time (DateTime.Now.ToString) instead of using the time that the form shows which is for a different time zone. The problem is that if it is 8 am in the eastern time zone and 7 am in central and so forth the wrong message shows up. What I need is the time on the form to be the reference point so if it is 7 am central time and 8 am eastern the correct message shows up for the corresponding time. Here is what I have I hope someone can help with this...
if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start 
                && (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end))
            {
                warningLabel.ForeColor = Color.Green;
                warningLabel.Text = "OK To Call";
            }
            else
            {
                warningLabel.ForeColor = Color.Red;
                warningLabel.Text = "Do Not Call";
            }
            if (DigitalClock.Text == "")
            {
                warningLabel.Text = "";
            }

Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5441
  • View blog
  • Posts: 11,676
  • Joined: 02-June 10

Re: timer1_Tick event problem

Posted 22 February 2011 - 10:08 PM

View PostEnderz, on 22 February 2011 - 04:49 PM, said:

I thought this was going to work but I still have a problem that I didn't notice at first on the application, the above information helped but the application still pulls the computers time (DateTime.Now.ToString) instead of using the time that the form shows which is for a different time zone. The problem is that if it is 8 am in the eastern time zone and 7 am in central and so forth the wrong message shows up. What I need is the time on the form to be the reference point so if it is 7 am central time and 8 am eastern the correct message shows up for the corresponding time. Here is what I have I hope someone can help with this...
if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start 
                && (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end))
            {
                warningLabel.ForeColor = Color.Green;
                warningLabel.Text = "OK To Call";
            }
            else
            {
                warningLabel.ForeColor = Color.Red;
                warningLabel.Text = "Do Not Call";
            }
            if (DigitalClock.Text == "")
            {
                warningLabel.Text = "";
            }


Funny how when you don't describe the situation with all the pertinent fact that the advice doesn't apply. YOu need to replace the use of DateTime.Now (which uses the PC time) with the DateTime property/variable you are using to display the clock on the form.

There is no code for how you are displaying a clock on the form. Nobody here knows what property that is, so I can't be more specific.
Was This Post Helpful? 0
  • +
  • -

#14 Enderz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 11

Re: timer1_Tick event problem

Posted 23 February 2011 - 07:16 AM

First of all I apologize for not explaining myself better concerning what I was actually trying to do. As far as your instructions tried several different ways to do this but I am not sure of the correct way to do this. The way I was trying to do it was to use the DigitalClock label and using the time displayed for the specific time zone and display the message based on that time zone. Here is all the code I have.
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 TimeZone
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void areaCodeDataBaseTableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.areaCodeDataBaseTableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.areaCodeDataBaseDataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'areaCodeDataBaseDataSet.AreaCodeDataBaseTable' table. 
            //You can move, or remove it, as needed.
            this.areaCodeDataBaseTableTableAdapter.Fill(this.areaCodeDataBaseDataSet.AreaCodeDataBaseTable);

        }

        private void DigitalClock_Load(object sender, EventArgs e)
        {
            Timer t = new Timer();
            t.Tick += new EventHandler(t_Tick);
            t.Interval = 1000;
            t.Enabled = true;
        }        

        public void t_Tick(Object Sender, EventArgs e)
        {            
            DateTime start = DateTime.Parse("08:00 am");
            DateTime end = DateTime.Parse("08:00 pm").AddHours(10);
            
            if (time_ZoneLabel1.Text == "Eastern")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(19).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Central")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Mountain")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Pacific")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(16).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Atlantic")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(20).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Hawaii-Aleutian")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(14).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "Eastern/Central")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(19).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "Central/Mountain")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(18).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "Mountain/Pacific")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
                DigitalClock2.Text = DateTime.UtcNow.AddHours(16).ToLongTimeString();
            }
            if (time_ZoneLabel1.Text == "UTC+10")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(10).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "UTC-10")
            {
                DigitalClock.Text = DateTime.UtcNow.AddHours(20).ToLongTimeString();
                DigitalClock2.Text = "";
            }
            if (time_ZoneLabel1.Text == "")
            {
                DigitalClock.Text = "";
                DigitalClock2.Text = "";                
            }
            if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start 
                && (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end))
            {
                warningLabel.ForeColor = Color.Green;
                warningLabel.Text = "OK To Call";
            }
            else
            {
                warningLabel.ForeColor = Color.Red;
                warningLabel.Text = "Do Not Call";
            }
            if (DigitalClock.Text == "")
            {
                warningLabel.Text = "";
            }        
        }        

        private void exitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }               
        
    }
}


Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5441
  • View blog
  • Posts: 11,676
  • Joined: 02-June 10

Re: timer1_Tick event problem

Posted 23 February 2011 - 07:53 AM

View PostEnderz, on 23 February 2011 - 08:16 AM, said:

First of all I apologize for not explaining myself better concerning what I was actually trying to do. As far as your instructions tried several different ways to do this but I am not sure of the correct way to do this. The way I was trying to do it was to use the DigitalClock label and using the time displayed for the specific time zone and display the message based on that time zone. Here is all the code I have.


Speaking just for myself, not on the behalf of DIC or it's management:
This is very obviously a program you are {probably} being paid to build for a telemarketing or collections company which is why their operators cannot call people at home outside of the hours of 8am-8pm. As such, I would assume you got the contract by underbidding someone who actually had the skill to write this but wanted more money *because* they actually could do the job. That type of thing is a personal pet peeve of mine. It bothers me to see people who have taken the time to learn loosing out on paying gigs by people who haven't underbidding them, then turning around and asking for free help from the very people they beat out. <stepping off of soap box now>

Getting back to the code itself. There are lots of problems with its design. It seems to be all about what you are showing with little consideration for the objects/values you need to actually get the job done. For example:
DigitalClock.Text = DateTime.UtcNow.AddHours(17).ToLongTimeString();
This shows some text for display but you don't actually make a DateTime object that you can work with, use to make decisions with and so on.

There is no consideration for where this PC is located geographically. You have hardcoded all your relative values. DateTime.UtcNow.AddHours(17) rather than make them calculate themselves based on the timezone of the PC. If you had done that the same application would work if it were in New York or California.

It was suggested to you earlier that you need to change the use of DateTime.Now to a DateTime object that represents the time in the target timezone. I don't see where you have tried to do that.

if (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) > start
                && (DateTime.Parse(DateTime.Now.ToString("HH:mm tt")) < end))
            {
                warningLabel.ForeColor = Color.Green;
                warningLabel.Text = "OK To Call";
            }


If you know that your DigitalClock.Text holds the time in the target zone and you have demonstrated a knowledge of how to parse a string to a DateTime, then I fail to understand why you haven't replaced DateTime.Now with the target time from DigitalClock.Text

In comparing the latest full code you just posted to your first full code when you opened the topic I see very little change. Honestly, I'm not seeing where you are putting in even as much effort as those trying to help you.

I'm sorry if my tone seems harsh. I do feel that you have reached well beyond your skill level and should take more time to learn before you try taking on professional jobs. I have shown you right where you need to make your change to get this to work and gave you as much as I dare without actually writing the corrected code for you.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3