-
July 21st, 2011, 06:23 PM
#1
HELP!!! Parking Calculator...
I am using Microsoft VB 2010. I am to calculate the charges for a parking garage. I was to use to a method to do the calculations and output the parking charges. My problem is that everything displays except for the charge... What am I doing wrong? Here is my code:
Public Class frmReyahAshford
Const MIN_FEE As Integer = 2.0
Const MIN_HOURS As Integer = 3
Const MAX_FEE As Integer = 10.0
Const OVER_CHARGE As Integer = 0.5
Const MAX_HOURS As Integer = 24
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtCharges.Clear()
txtHours.Clear()
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim hours As Double
hours = txtHours.Text
CalculateCharges(hours)
End Sub
Sub CalculateCharges(ByVal hoursparked)
Dim charge As Double
Dim newHours As Double
If (hoursparked > MIN_HOURS And hoursparked < MAX_HOURS) Then
newHours = hoursparked - MIN_HOURS
charge = (newHours * OVER_CHARGE) + MIN_FEE
txtCharges.Text = String.Format("{0:C}", charge)
End If
If hoursparked = MAX_HOURS Then
txtCharges.Text = String.Format("{0:C}", MAX_FEE)
ElseIf hoursparked <= MIN_HOURS Then
txtCharges.Text = String.Format("{0:C}", MIN_FEE)
End If
If hoursparked > 24 Then
txtCharges.Text = "You're car was towed!"
txtCharges.ForeColor = Color.Red
End If
End Sub
-
July 21st, 2011, 09:03 PM
#2
Re: HELP!!! Parking Calculator...
Your hoursparked is not defined properly in the sub header.
You are assigning the value of a textbox to a var defined as a double, could cause program to crash.
You are then sending the double to a sub where the var type is not defined, could be an issue.
You have hard coded 24 in the last if statement where you should have used MAX_HOURS instead.
In your string format statements you are treating numeric variables as if they were a string var.
use [ code] [ /code ] tags when posting code to keep the formatting and make it easier to read.
Always use [code][/code] tags when posting code.
-
July 21st, 2011, 11:10 PM
#3
Re: HELP!!! Parking Calculator...
And submit $0.25 for the tutoring. Just Kidding! (Out of rating points here)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|