Split Days and Time

This code enables you to convert or split the input of days, hours, minutes, seconds and milliseconds to assign them on each textbox and determine what was your input but you need to follow the correct format to work the program properly.

Open your Visual Basic .NET Application.

Step 1:
Create a New Project, go to File Menu and navigate to New > Project and put a project name of ConvertDaysTime.

Step 2:

Create the following objects:
1 – Frame (TEXT PROPERTIES: Days and Time)
1 – Button (TEXT PROPERTIES: Convert)
5 – Labels (TEXT PROPERTIES: Days, Hours, Minutes, Seconds, Miliseconds)
6 – Textbox (NAME PROPERTIES: txtConvert, txtDays, txtHours, txtMinutes, txtSeconds, txtMili)

Step 3:
Put this code in your code editor
Public Class frmConvertDays

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtConvert.Text = "4.12:59:06.12" 'You can change the content of this string value
    End Sub
    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
            txtDays.Text = TSpan.Days.ToString
            txtHours.Text = TSpan.Hours.ToString
            txtMinutes.Text = TSpan.Minutes.ToString
            txtSeconds.Text = TSpan.Seconds.ToString
            txtMili.Text = TSpan.Milliseconds.ToString
        Catch ex As Exception
            MsgBox(ex.Message, Me.Text)
        End Try
    End Sub

    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(txtConvert.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
End Class

Final Output


Split Days and Time Split Days and Time Reviewed by code-dev on 4:11 PM Rating: 5

No comments:

Powered by Blogger.