Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15072

VS 2019 Old man needs help

$
0
0
Good day all. Firstly, please forgive such a stupid question. I am 54 years old and have only a few months ago started with vb.net after I lost my job in aviation due to covid. This is all new to me and I had a choice of either lying down or trying to get back on my feet. A mate recommended vb.net and not C# as I am new to this whole programming thing. I have a few friends that are helping me get small jobs doing desktop programs. I have a possible new client that would like to have a small program that calculates hours for her staff. Yes, excel can do it but she wants a program.

What I am trying to do is calculate two times. It works fine, except when the later time is the next day. For example: Shift is from 22:00 till 06:00, the shift must read 08:00 hours. Currently I am getting -16 hours. I have googled but I am having a really hard time with this.

Below is the code for the button. Please forgive the primitive coding :)

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim TimeOn As DateTime = DateTime.Parse(MaskedTextBox1.Text)
Dim TimeOff As DateTime = DateTime.Parse(MaskedTextBox2.Text)
Dim timeDiff As TimeSpan = TimeOff.Subtract(TimeOn)

' Here I need to figure out how to calculate the time if
' TimeOff is the next day. Eg. Shift is 22:00 till 06:00
' the answer should be 08:00 (8 hours)

TextBox1.Text = (timeDiff.ToString)
End Sub
End Class

Viewing all articles
Browse latest Browse all 15072

Trending Articles