Private Sub total()
Dim mydate As Integer = 0 'เงินเพิ่ม
Dim total As Integer = 0 'รวม
Dim pay As Integer = 0 'จำนวนเงินที่ต้องจ่าย
Dim diffTime As TimeSpan = DateTimePicker2.Value - DateTimePicker1.Value
mydate = CInt(diffTime.Days) + 1
mydate = Val(Label5.Text)
total = Val(Label20.Text)
pay = Val(Label11.Text)
If mydate < 15 Then
Label5.Text = 0
Else
mydate = total * 0.1 'จำนวนเงินที่ต้องจ่าย * 10/100
pay = total + mydate
Label5.Text = CStr(mydate) 'CStr() ฟังก์ชัน แปลงตัวเลขให้กลับมาเป็นข้อความ'
Label11.Text = CStr(pay)
End If
Label5.Text = mydate.ToString("#,##0.00")
Label11.Text = pay.ToString("#,##0.00")
Label20.Text = total.ToString("#,##0.00")
End Sub
Code (VB.NET)
Private Sub DateTimePicker2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
total()
Dim temp As Integer
Dim wD As Long = DateDiff(DateInterval.Day, DateTimePicker1.Value, DateTimePicker2.Value)
dateDiffs = wD
If dateDiffs > 15 Then
Label5.Text = Val(Label20.Text) * 0.1
Label5.Text = temp
Label11.Text = Val(Label20.Text) + temp
Else
Label11.Text = Label20.Text
End If
End Sub