How to Count or Calculate Days in Visual Basic.Net

This tutorial is all about How to Count or Calculate Days in Visual Basic.Net. With this tutorial you can Count or Calculate Days in Visual Basic.Net easily. In this article, I’ll show you how to compute the difference in age between two ages. I’ve used two LabelBoxes, two TextBoxes, and one Button in this.

LabelBox is used to display things, and it may be displayed by selecting properties from the properties panel. On a Form, a TextBox is used to accept user input. When we click on a button, it displays the output. I’ve also utilized validation in this, which is used to set a limit on any TextBox. If we enter a number that is longer than two digits, it will return an invalid value. The steps to take are listed below.

So let’s get started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Design your form like this just like what I’ve shown you below.
    Add 2 DatetimePicker, 3 Label, Textbox and a Button.
  • After Designing your form, Add this code to the button.

[vbnet]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim First As Date
Dim Second As Date
Dim Result As New TimeSpan()
First = DateTimePicker1.Value
Second = DateTimePicker2.Value
Result = Second – First
Me.TextBox1.Text = FormatNumber(Result.TotalDays.ToString, 2)
End Sub

[/vbnet]

  • Finally, Click F5 to run Program.

Output:

If you have any comments or suggestion about on How to Count or Calculate Days in Visual Basic.Net, Please Feel Free to contact our webpage.

Download Source Code! Here

Other articles you might read also:

Leave a Comment