基于VB.Net中的两个文本框中的时间差计算要支付的金额
我想得到的金额支付的基础上的时间差的时间和超时。 例子。时间是:7:00:00 暂停时间为:13:00:00 相差6小时 假设每小时的费率是10.00,那么金额应该是60.00 谢谢我正在使用vb.net 我想做的就是这样基于VB.Net中的两个文本框中的时间差计算要支付的金额,vb.net,Vb.net,我想得到的金额支付的基础上的时间差的时间和超时。 例子。时间是:7:00:00 暂停时间为:13:00:00 相差6小时 假设每小时的费率是10.00,那么金额应该是60.00 谢谢我正在使用vb.net 我想做的就是这样 Private Const Format As String = "HH:mm:ss" 'this is the code i used to get the time in Private Sub btnTimeIn_Click(sender As Object, e A
Private Const Format As String = "HH:mm:ss"
'this is the code i used to get the time in
Private Sub btnTimeIn_Click(sender As Object, e As EventArgs) Handles btnTimeIn.Click
TextboxTimeIn.Text = DateTime.Now.ToString(Format)
End Sub
'this is the time out
Private Sub btnTimeOut_Click(sender As Object, e As EventArgs) Handles btnTimeOut.Click
TextboxTimeOut.Text = DateTime.Now.ToString(Format)
'this is what is use to get the time difference
txtAmount.Text = Convert.ToDateTime(TextboxTimeOut.Text).Subtract(Convert.ToDateTime(TextboxTimeIn.Text)).ToString()
End Sub
但我不想显示时差,而是想在txtAmount中显示金额。范例
如果时差为60分钟,则
txtAmount=20你想知道三件事:
'let's use some more variables to make this easier
Private Const Format As String = "HH:mm:ss"
Private checkin As DateTime
Private checkout As DateTime
Private rate As Integer = 10
'now with variables!
Private Sub btnTimeIn_Click(sender As Object, e As EventArgs) Handles btnTimeIn.Click
checkin = Now
TextboxTimeIn.Text = checkin.ToString(Format)
End Sub
Private Sub btnTimeOut_Click(sender As Object, e As EventArgs) Handles btnTimeOut.Click
checkout = Now
TextboxTimeOut.Text = checkout.ToString(Format)
'First we check for an amount of hours, then we add one if they overstayed
Dim timeStayed As Integer = checkout.Hour - checkin.Hour
If TimeStayed.Minute > 0 Then timeStayed += 1
'Notice the use of a variable so you can tweak your rates easily
txtAmount.Text = (timeStayed * rate).ToString
End Sub
您需要记住的是:
请提供一个最低限度的验证您的尝试的例子:我很抱歉,因为我是新的编码。你可以在所附的图片中看到我想说的话。谢谢你能看到我有时间进出。当我单击中的时间时,它将转到文本框中的时间。当我单击“超时”时,它会计算两者的时间差。但我想要的是,我不想显示金额的时差,而是想看到它与价格的转换。这是每小时10php。你有任何与你的问题有关的代码吗?例如,当您在“如何显示时间?”中单击“时间”时,请参见“我编辑的问题”。非常感谢。