DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   how can I calculate the fee ?? (http://www.daniweb.com/forums/thread120450.html)

miss.A Apr 22nd, 2008 12:35 pm
how can I calculate the fee ??
 
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

ericstenson Apr 23rd, 2008 12:39 am
Re: how can I calculate the fee ??
 
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

ericstenson Apr 23rd, 2008 12:40 am
Re: how can I calculate the fee ??
 
sorry, as DECIMAL, not Long...

and Button1.Text = FormatCurrency(TCost)

miss.A Apr 23rd, 2008 11:00 am
Re: how can I calculate the fee ??
 
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...

miss.A Apr 23rd, 2008 11:07 am
Re: how can I calculate the fee ??
 
soo0oory .. No Dim errorflag As Boolean


All times are GMT -4. The time now is 6:35 pm.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC