I have to create an application that calculate parking garage fee by using VB.Net and use timepicker for time in and time out.
For each hour it cost 3$ and it calculate minutes as 1\60.

I start coding but I face problem with how can I calculate the fee and the car can’t stay overnight.. it should leave in same day…


This is my code…


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim HourlyRate As Decimal
Dim TimeIn As Double
Dim TimeOut As Double
Dim calculat As Double

HourlyRate = 3
TimeIn = DateTimePicker1.Text
TimeOut = DateTimePicker2.Text

calculat = Fee(DateTimePicker1.Text, DateTimePicker2.Text, HourlyRate)
Label1.Text = calculat.ToString + "$"
End Sub


Function Fee(ByVal TimeIn As Integer, ByVal TimeOut As Integer, _
ByVal HourlyRate As Decimal) As Decimal

Dim calculat As Double

calculat = (TimeIn - TimeOut) * HourlyRate
Return calculat

End Function


End Class

i would do it like....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim THours As Integer = DateTimePicker2.Value.Hour - DateTimePicker1.Value.Hour
        Dim TMinutes As Integer = DateTimePicker2.Value.Minute - DateTimePicker1.Value.Minute

        Dim TCost As Long


        If TMinutes >= 0 Then

            TCost = (3 * THours) + (3 * (TMinutes / 60))

        Else

            TMinutes = (-1) * TMinutes
            TCost = (3 * THours) - (3 * (TMinutes / 60))


        End If



        Button1.Text = TCost

sorry, as DECIMAL, not Long...

and Button1.Text = FormatCurrency(TCost)

mmmm...

i do it in this way


Public Class Form1

Dim TimeInHou As Integer
Dim TimeOutHou As Integer
Dim TimeInMun As Integer
Dim TimeOutMun As Integer
Dim errorflag As Boolean


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TimeInHou = DateTimePicker1.Value.Hour
TimeOutHou = DateTimePicker2.Value.Hour

TimeInMun = DateTimePicker1.Value.Minute
TimeOutMun = DateTimePicker2.Value.Minute

Dim calculat As Double

If TimeOutHou > TimeInHou Then

calculat = ((DateTimePicker2.Value.Hour - DateTimePicker1.Value.Hour) + ((DateTimePicker2.Value.Minute - DateTimePicker1.Value.Minute) \ 60)) * 3

Label1.Text = calculat.ToString + "$"
End If

End Sub

Function Fee(ByVal TimeInHou As Integer, ByVal TimeOutHou As Integer, ByVal TimeInMun As Integer, ByVal TimeOutMun As Integer) As Integer

Dim calculat As Double
calculat = ((TimeOutHou - TimeInHou) + ((TimeOutMun - TimeInMun) \ 60)) * 3

End Function
End Class


it works ... but i don't know how to validate this so the car should leave in same day and no park at overnight...

soo0oory .. No Dim errorflag As Boolean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.