please i want someone to help me out here. i am trying to develop a dynamic class timetable.
Every 2hrs; classes change lectures and lecturerers. i want my application on its own to be able to switch to next period. Doing that, the next period lctures and the lectureers would display on the thesame labels that previous lectures displayed. i am using "System.Windows.Forms.Timer" and
"TimerEventProcessor" to trigger the methods that will display the ongoing lectures and the lecturerers.
After so many efforts i made; nothing seemed to happen.
please i need help. here is the code:

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 WindowsFormsApplicationtimer
{
    public partial class Form1 : Form
    {
       // fixed time for lectures and thier respective lecturerers to display
        string timethen = "9:08:00 PM";
        string timethen2 = "7:08:01 PM";
        string timethen3 = "7:08:02 PM";
        string newtime = Convert.ToString(System.DateTime.Now);
        static System.Windows.Forms.Timer theTimer =
         new System.Windows.Forms.Timer();
        static int alarmCounter = 1;
        static bool exitFlag = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void TimerEventProcessor(Object myObject,
          EventArgs myEventArgs)
        {
            // calling these methods every seconds
                alarmCounter += 1;
                theTimer.Enabled = true;
                repitdisplay();
                repitdisplay2();
            
                exitFlag = true;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            theTimer.Tick += new EventHandler(TimerEventProcessor);

            
            theTimer.Interval = 100;
            theTimer.Start();

            // Runs the timer, and raises the event
            while (exitFlag == false)
            {
                // Processes all the events in the queue
                Application.DoEvents();
            }
            
        }
        void repitdisplay()
        {
            label2.Text = DateTime.Now.ToLongTimeString();

            if ((string.Compare(timethen, newtime) == 0) || (string.Compare(timethen3, newtime) == 0) || (string.Compare(timethen2, newtime) == 0))
            {
               // possibly to be called from the database
                string disp = "Cos201";
               string disp1 = "Cos401";
                label1.Text = disp.ToString();
                label4.Text = disp1.ToString();
            }

        }
        void repitdisplay2()
        {

            if ((string.Compare(timethen, newtime) != 0) || (string.Compare(timethen3, newtime) != 0) || (string.Compare(timethen2, newtime) != 0))
            {
                // possibly to be called from the database
                string disp = "Mth 321";
               string disp1 = "Stat 432";
                label1.Text = disp.ToString();
                label4.Text = disp1.ToString();
            }

        }
Member Avatar for Unhnd_Exception
namespace WindowsFormsApplicationtimer
namespace WindowsFormsApplicationtimer
{
    public partial class Form1 : Form
    {

        Dictionary<string, string> Classes;
        System.Windows.Forms.Timer theTimer;

        public Form1()
        {
            InitializeComponent();

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

            // fixed time for lectures and thier respective lecturerers to display
            Classes = new Dictionary<string, string>();
            Classes.Add("9:08 PM", "COS201;COS401");
            Classes.Add("7:08 PM", "Math321;Stat432");
        }

        private void TimerEventProcessor(Object myObject,
          EventArgs myEventArgs)
        {
            // calling these methods every seconds

            string newtime = System.DateTime.Now.ToShortTimeString();
            label2.Text = newtime;

            if (Classes.ContainsKey(newtime))
            {
                // possibly to be called from the database
                string[] splitter = Classes[newtime].Split(new char[]{';'});
                label1.Text = splitter[0];
                label4.Text = splitter[1];
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            theTimer.Tick += new EventHandler(TimerEventProcessor);

            theTimer.Interval = 15000; //every 15 seconds
            theTimer.Start();
        }

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.