CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Unhappy 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

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: HELP!!! Parking Calculator...

    And submit $0.25 for the tutoring. Just Kidding! (Out of rating points here)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured