Converting Days And Time in VB.Net

This tutorial is all about Converting Days And Time in VB.Net.
In this tutorial I will teach you how to convert the days and time in VB.Net. With this, you can segregates the combined days and time (2.06:58:08.32) into days, hours, minutes, seconds and milliseconds. This will help you and easily identify its different fields.

What is Visual Basic’s purpose?

The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files. They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.

However, there are some limits to the Microsoft Visual Basic download. If you want to make applications that take a long time to process, this software isn’t for you. That implies you won’t be able to use VB to create games or large apps because the system’s graphic interface requires a lot of memory and space. Furthermore, the language is limited to Microsoft and does not support other operating systems.

What are the most important characteristics of Visual Basic?

Microsoft Visual Basic for Applications Download, unlike other programming languages, allows for speedier app creation. It has string processing capabilities and is compatible with C++, MFC, and F#. Multi-targeting and the Windows Presentation Framework are also supported by the system, allowing developers to create a variety of Windows apps, desktop tools, metro-style programs, and hardware drivers.

Let’s begin:
Open the Visual Basic, create a new Windows Form Application and do the Form just like this.
daystimeconverterform
After setting up the Form, double click the Form and create a sub procedure above the Form1_Load for separating the days and time.

[vbnet]
Private Sub Parse_Days_Time(ByVal TSpan As TimeSpan)
‘IN USING THE PROPERTIES OF THE TIMESPAN, IT WILL SEPERATE THE DAYS AND TIME
‘ IT DEMONSTRATES THE TimeSpan.Days, TimeSpan.Hours,
‘ TimeSpan.Minutes, TimeSpan.Seconds
‘ AND TimeSpan.Milliseconds
Try
txt_days.Text =TSpan.Days.ToString
txt_hours.Text = TSpan.Hours.ToString
txt_minute.Text = TSpan.Minutes.ToString
txt_second.Text = TSpan.Seconds.ToString
txt_millisecond.Text = TSpan.Milliseconds.ToString

Catch ex As Exception
MsgBox(ex.Message, Me.Text)
End Try
[/vbnet]

In the Form1_Load, you have to set the constant value of the days and time in the TextBox.

[vbnet]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘SET THE STRING VALUE IN THE TEXTBOX
txt_daysTime.Text = “4.12:59:06.12”
End Sub
[/vbnet]

Lastly, go to the design views, double click the “convert” Button and set the Sub Procedure that you have created in the Click event handler of the Button.

[vbnet]
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Try
Dim TSpan As TimeSpan
‘CONVERTS THE STRING VALUE INTO TIMESPAN
TSpan = TimeSpan.Parse(txt_daysTime.Text)

‘SET THE VALUE OF THE TIMESPAN
‘TO THE PARAMETER OF THE SUB PROCEDURE THAT YOU HAVE CREATED.
Parse_Days_Time(TSpan)
Catch ex As Exception
MsgBox(Me.Text, ex.Message)
End Try
End Sub
[/vbnet]

Download the complete source code and run it on your computer.

Readers might read also:

Leave a Comment