Lecture-08 Handling Higher Math
Lecture-08 Handling Higher Math
Visual Programming
• int y = age.Year - 1;
• int m = age.Month - 1;
• int d = age.Day - 1;
• textBox1.Text = y.ToString() +" / " +m.ToString() +" / " + d.ToString();
Using format to display dates and time
• Dt.ToString(“M-d-yy")); // 1-1-15
• Dt.ToString(“MM-dd-yy")); // 05-31-15
• Dt.ToString(“M/d/yy")); // 1/1/15
• Dt.ToString(“ddd,MMMM d, yyy")); // sundy, January 1, 2015
• Dt.ToString(“hh:mm:ss MM/dd/yy")); // 12:20:50 05/07/15
• Dt.ToString(“hh:mm:ss tt MM-dd-yyy")); // 01:00:00 AM 11-18-2015
The timer Control
• The Timer control is essentially an invisible stopwatch that gives you access to
the system clock in your programs.
• The Timer control can be used like an egg timer to count down from a preset
time, to cause a delay in a program, or to repeat an action at prescribed
intervals.
• You set a timer’s interval by using the Interval property, and you activate a
timer by setting the timer’s Enabled property to True Once a timer is enabled, it
runs constantly until the user stops the program or the timer object is disabled
Creating a Digital Clock by Using a Timer
Control
• Create project, drags and set the properties for the object given
• Double-click the timer object in the component tray The Timer1_Tick event
procedure appears in the Code Editor This is the event procedure
• that runs each time that the timer clock ticks Type the following statement:
Label1.Text = DateTime.now.ToShortTimeString();
Using a Timer object to set a time limit
Sample Project
DateTime stoptime;
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 1000;
TimeSpan duration = TimeSpan.Parse(textBox1.Text);
stoptime = DateTime.Now.Add(duration);
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan remaining = stoptime.Subtract(DateTime.Now);
remaining = new TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds);
if (remaining.TotalSeconds < 0)
{
remaining = TimeSpan.Zero;
this.WindowState = FormWindowState.Maximized;
this.TopMost = true;
timer1.Enabled = false;
}
label1.Text = remaining.ToString();
}
Inserting Code Snippets
• In the Code Editor, position the insertion point (I-beam) at the location where
you want to insert the snippet
• On the Edit menu, click IntelliSense, and then click Insert Snippet Browse to the
snippet that you want to use, and then double-click the snippet name.
3 Types of Error
• A syntax error (or compiler error) is a mistake (such as a misspelled property or keyword) that
violates the programming rules of Visual C# Visual C# will point out several types of syntax
errors in your programs while you enter program statements, and it won’t let you run a
program until you fix each syntax errors.
• A run-time error is a mistake that causes a program to stop unexpectedly during execution
Run-time errors occur when an outside event or an undiscovered run-time error forces a
program to stop while it’s running For instance, if you try to read a disk drive and it doesn’t
contain a CD or DVD, your code will generate a run-time error.
• A logic error is a human error—a mistake that causes the program code to produce the wrong
results Most debugging efforts are focused on tracking down logic errors introduced by the
programmer.
Using Debugging
• In debugging mode, you have an opportunity to see how the logic in your program is
evaluated.
• Tracking Variables by Using a Watch Window
• Visualizers: Debugging Tools That Display Data
• Using the Immediate (are used if immediately we want change in running program)
• Type >immed for immediate window