This VB.NET Windows Forms application demonstrates the use of the DateTimePicker control to select a date and extract its day, month, and year values. The selected date is displayed in separate TextBox controls, highlighting effective DateTime handling in Visual Basic .NET.
Slip 4 Q.A) Problem Statement
Q. Design a VB.NET form to pick a date from DateTimePicker Control and display day, month, and year in separate text boxes. 15 Marks
Answer:
Algorithm / Logic
- Select a date using the DateTimePicker control.
- Click the Show Button.
- Get the selected date using the
Valueproperty. - Extract Day, Month, and Year from the selected date.
- Display the values in separate TextBox controls.
Source Code
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = "Year : " & DateTimePicker1.Value.Year
Label2.Text = "Month : " & DateTimePicker1.Value.Month
Label3.Text = "Day : " & DateTimePicker1.Value.Day
End Sub
End Class
FAQ Section
1. What is a DateTimePicker control?
A DateTimePicker control is used to allow the user to select a date (and/or time) from a calendar or drop-down list in a Windows Forms application.
2. Which property is used to get the selected date?
The Value property is used to get the selected date from the DateTimePicker control.
3. What data type is returned by DateTimePicker.Value?
DateTimePicker.Value returns a DateTime data type.
4. Why do we use .ToString() in the program?
We use .ToString() to convert numeric or DateTime values into string format so they can be displayed in a TextBox.
5. Which event is used when the button is clicked?
The Click event is used when the button is clicked.
