В проекте рассмотрены функции даты и времени: текущие дата и время, день недели, день месяца, день года, проверка на високосный год, максимальное и минимальное значение в интервале измерения времени, год, день, разность дат. Для каждой функции создается текстовое поле аргумента функции, текстовое результирующее поле, кнопка с названием функции. Управляющие элементы функций, использующих одинаковые исходные поля аргументов окрашены в один цвет.
Программный код Public Class Form1 Dim d1 As DateTime = DateTime.Now Dim d10, d11 As DateTime Dim d2 As Date Dim k As Integer Dim vis As Boolean Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = DateTime.Now End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click d2 = TextBox2.Text k = d2.DayOfWeek Select Case k Case 1 TextBox13.Text = "Понедельник" Case 2 TextBox13.Text = "Вторник" Case 3 TextBox13.Text = "Среда" Case 4 TextBox13.Text = "Четверг" Case 5 TextBox13.Text = "Пятница" Case 6 TextBox13.Text = "Суббота" Case 7 TextBox13.Text = "Воскресенье" End Select End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click d2 = TextBox2.Text TextBox14.Text = d2.Year End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox15.Text = Now() End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click d2 = TextBox2.Text TextBox14.Text = d2.Year End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox15.Text = Now() End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click d2 = TextBox2.Text TextBox14.Text = d2.Year End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox15.Text = Now() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click d2 = TextBox2.Text TextBox16.Text = Str(d2.Day) End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click d2 = TextBox2.Text TextBox17.Text = d2.DayOfYear End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click TextBox22.Text = DateTime.MinValue End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click TextBox21.Text = DateTime.MaxValue End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click TextBox18.Text = Today() End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click d2 = TextBox8.Text k = d2.Year vis = DateTime.IsLeapYear(k) If vis = True Then TextBox20.Text = "Високосный" Else TextBox20.Text = "Невисокосный" End If End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Dim diff1 As System.TimeSpan d10 = TextBox10.Text d11 = TextBox11.Text diff1 = System.DateTime.op_Subtraction(d10, d11) TextBox19.Text = Str(diff1.Days) + " дней " + Str(diff1.Hours) + " часов " + Str(diff1.Minutes) + " минут" End Sub End Class