Results 1 to 2 of 2

Thread: [RESOLVED] Property Procedure Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    [RESOLVED] Property Procedure Help

    VB Code:
    1. Private Sub calculateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calculateButton.Click
    2.  
    3.         Dim discountDecimal, dailyRateDecimal, miRateDecimal As Decimal
    4.         Dim chargeMiBoolean As Boolean
    5.         Const NONE_DISCOUNT_Decimal As Decimal = 1D
    6.         Const CORP_DISCOUNT_Decimal As Decimal = 0.95D
    7.         Const INS_DISCOUNT_Decimal As Decimal = 0.9D
    8.         Const COMPACT_DAILY_RATE_Decimal As Decimal = 26.95D
    9.         Const COMPACT_MI_RATE_Decimal As Decimal = 0.12D
    10.         Const MID_DAILY_RATE_Decimal As Decimal = 32.95D
    11.         Const MID_MI_RATE_Decimal As Decimal = 0.15D
    12.         Const LUXURY_DAILY_RATE_Decimal As Decimal = 50.95D
    13.         Const LUXURY_MI_RATE_Decimal As Decimal = 0.2D
    14.  
    15.         If Me.noneRadioButton.Checked Then
    16.             discountDecimal = NONE_DISCOUNT_Decimal
    17.             chargeMiBoolean = True
    18.         End If
    19.         If Me.corporateRadioButton.Checked Then
    20.             discountDecimal = CORP_DISCOUNT_Decimal
    21.             chargeMiBoolean = False
    22.         End If
    23.         If Me.insuranceRadioButton.Checked Then
    24.             discountDecimal = INS_DISCOUNT_Decimal
    25.             chargeMiBoolean = True
    26.         End If
    27.         If Me.compactRadioButton.Checked Then
    28.             dailyRateDecimal = COMPACT_DAILY_RATE_Decimal
    29.             miRateDecimal = COMPACT_MI_RATE_Decimal
    30.         End If
    31.         If Me.midsizeRadioButton.Checked Then
    32.             dailyRateDecimal = MID_DAILY_RATE_Decimal
    33.             miRateDecimal = MID_MI_RATE_Decimal
    34.         End If
    35.         If Me.luxuryRadioButton.Checked Then
    36.             dailyRateDecimal = LUXURY_DAILY_RATE_Decimal
    37.             miRateDecimal = LUXURY_MI_RATE_Decimal
    38.         End If
    39.  
    40.         Dim myCalc As New CalculationsClass(Decimal.Parse(Me.totalMiTextBox.Text), Integer.Parse(Me.daysRentedTextBox.Text), discountDecimal, chargeMiBoolean, dailyRateDecimal, miRateDecimal)
    41.  
    42.         Me.amountDueTextBox.Text = myCalc.AmountDue.ToString("C")
    43.         Debug.WriteLine("Check number before passing")
    44.         Debug.WriteLine("discount=" & discountDecimal.ToString())
    45.         Debug.WriteLine("TotalMi=" & totalMiTextBox.Text.ToString())
    46.         Debug.WriteLine("DailyRate=" & dailyRateDecimal.ToString())
    47.         Debug.WriteLine("MiRate=" & miRateDecimal.ToString())
    48.         Debug.WriteLine("DaysRented=" & daysRentedTextBox.Text.ToString())
    49.     End Sub
    VB Code:
    1. Public Class CalculationsClass
    2.     Private discountDecimal, dailyRateDecimal, miRateDecimal, amountDecimal, discountApply As Decimal
    3.     Private daysRentedInteger, totalMiInteger As Integer
    4.     Private chargeMiInBoolean As Boolean
    5.  
    6.     Sub New(ByVal totalMiInInteger As Integer, ByVal daysRentedInInteger As Integer, ByVal discountInDecimal As Decimal, ByVal chargeMiInBoolean As Boolean, ByVal dailyRateInDecimal As Decimal, ByVal miRateInDecimal As Decimal)
    7.         'constructor method
    8.         Discount = discountInDecimal
    9.         TotalMi = totalMiInInteger
    10.         DailyRate = dailyRateInDecimal
    11.         MiRate = miRateInDecimal
    12.         DaysRented = daysRentedInInteger
    13.  
    14.         If ((TotalMi / DaysRented) < 100) Or chargeMiInBoolean Then
    15.             MiRate = 0
    16.         End If
    17.         amountDecimal = Discount * ((DailyRate * DaysRented) + (TotalMi * MiRate))
    18.  
    19.         Debug.WriteLine("Check number after passing")
    20.         Debug.WriteLine("discount=" & Discount.ToString())
    21.         Debug.WriteLine("TotalMi=" & TotalMi.ToString())
    22.         Debug.WriteLine("DailyRate=" & DailyRate.ToString())
    23.         Debug.WriteLine("MiRate=" & miRate.ToString())
    24.         Debug.WriteLine("DaysRented=" & DaysRented.ToString())
    25.     End Sub
    26.  
    27.     Private Property Discount() As Decimal
    28.         Get
    29.  
    30.         End Get
    31.         Set(ByVal value As Decimal)
    32.             discountDecimal = value
    33.         End Set
    34.     End Property
    35.  
    36.     Private Property TotalMi() As Integer
    37.         Get
    38.  
    39.         End Get
    40.         Set(ByVal value As Integer)
    41.             totalMiInteger = value
    42.         End Set
    43.     End Property
    44.     Private Property DailyRate() As Decimal
    45.         Get
    46.  
    47.         End Get
    48.         Set(ByVal value As Decimal)
    49.             dailyRateDecimal = value
    50.         End Set
    51.     End Property
    52.     Private Property DaysRented() As Integer
    53.         Get
    54.  
    55.         End Get
    56.         Set(ByVal value As Integer)
    57.             daysRentedInteger = value
    58.         End Set
    59.     End Property
    60.     Private Property MiRate() As Decimal
    61.         Get
    62.  
    63.         End Get
    64.         Set(ByVal value As Decimal)
    65.             miRateDecimal = value
    66.         End Set
    67.     End Property
    68.     Public ReadOnly Property AmountDue() As Decimal
    69.         Get
    70.             Return (amountDecimal)
    71.         End Get
    72.     End Property
    73. End Class

    I can't seem to pass on the varibles. When I check the values of all the ones on the left of the "=" is zero, while the varibles on the right side of the "=" is the correct value.
    VB Code:
    1. Discount = discountInDecimal
    2.         TotalMi = totalMiInInteger
    3.         DailyRate = dailyRateInDecimal
    4.         MiRate = miRateInDecimal
    5.         DaysRented = daysRentedInInteger
    Last edited by mrman99; Sep 21st, 2006 at 08:46 PM.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Property Procedure Help

    You're missing the code inside the get statement. Use an underscore infront of your private variables to make them different from the incomming values in your constructor. Also, do you have options strict and excplicit on?
    Try this:
    VB Code:
    1. Sub New(ByVal totalMiInInteger As Integer, ByVal daysRentedInInteger As Integer, ByVal discountInDecimal As Decimal, ByVal chargeMiInBoolean As Boolean, ByVal dailyRateInDecimal As Decimal, ByVal miRateInDecimal As Decimal)
    2.         'constructor method
    3.         _discountDecimal = discountInDecimal
    4.         _totalMiInteger = totalMiInInteger
    5.         _dailyRateDecimal = dailyRateInDecimal
    6.         _miRateDecimal = miRateInDecimal
    7.         _daysRentedInteger = daysRentedInInteger
    8.  
    9.         If ((TotalMi / DaysRented) < 100) Or chargeMiInBoolean Then
    10.             MiRate = 0
    11.         End If
    12.         _amountDecimal = Discount * ((DailyRate * DaysRented) + (TotalMi * MiRate))
    13.  
    14.         Debug.WriteLine("Check number after passing")
    15.         Debug.WriteLine("discount=" & Discount.ToString())
    16.         Debug.WriteLine("TotalMi=" & TotalMi.ToString())
    17.         Debug.WriteLine("DailyRate=" & DailyRate.ToString())
    18.         Debug.WriteLine("MiRate=" & miRate.ToString())
    19.         Debug.WriteLine("DaysRented=" & DaysRented.ToString())
    20.     End Sub
    21.  
    22.     Private Property Discount() As Decimal
    23.         Get
    24.             Return _discountDecimal
    25.         End Get
    26.         Set(ByVal value As Decimal)
    27.             _discountDecimal = value
    28.         End Set
    29.     End Property
    30.  
    31.     Private Property TotalMi() As Integer
    32.         Get
    33.             Return _totalMiInteger
    34.         End Get
    35.         Set(ByVal value As Integer)
    36.             _totalMiInteger = value
    37.         End Set
    38.     End Property
    39.     Private Property DailyRate() As Decimal
    40.         Get
    41.             Return _dailyRateDecimal
    42.         End Get
    43.         Set(ByVal value As Decimal)
    44.             _dailyRateDecimal = value
    45.         End Set
    46.     End Property
    47.     Private Property DaysRented() As Integer
    48.         Get
    49.             Return _daysRentedInteger
    50.         End Get
    51.         Set(ByVal value As Integer)
    52.             _daysRentedInteger = value
    53.         End Set
    54.     End Property
    55.     Private Property MiRate() As Decimal
    56.         Get
    57.             Return _miRateDecimal
    58.         End Get
    59.         Set(ByVal value As Decimal)
    60.             _miRateDecimal = value
    61.         End Set
    62.     End Property
    63.     Public ReadOnly Property AmountDue() As Decimal
    64.         Get
    65.             Return _amountDecimal
    66.         End Get
    67.     End Property
    68. End Class

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