Results 1 to 3 of 3

Thread: Help with Code

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Help with Code

    Hi there, I am trying to get the calculation done in the Function "OtherCharges" into a module to do calculation. I keep coming accross errors. When I fix one thing another is mysteriously not functioning any longer. HELP! This is an assignment due this week. I am sure I have more than one issue here, I am just learning.

    Here the form I am trying to get the data from. The specific issue is that I must get the user input from the text box to the module. One error I get is with the variable "decAlt" I am told an error bc of string to boolean. Second, on the variable "dtmSystemDate"
    vb.net Code:
    1. Public Class frmAlterations
    2.  
    3.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    4.         Dim decAlter As Decimal
    5.         decAlter = OtherCharges()
    6.  
    7.         frmMain.lblOther.Text = decAlter.ToString("c")
    8.  
    9.         If radHemSimple.Checked Then
    10.             frmMain.lstProducts.Items.Add("Hem, Simple")
    11.         ElseIf radHemMultipleLayers.Checked Then
    12.             frmMain.lstProducts.Items.Add("Hem, Multiple Layers")
    13.         ElseIf radHemComplex.Checked Then
    14.             frmMain.lstProducts.Items.Add("Hem, Complex")
    15.  
    16.             CalculatePlan()
    17.         End If
    18.  
    19.         If radBustleShort.Checked Then
    20.             frmMain.lstProducts.Items.Add("Bustle, Short")
    21.         ElseIf radBustleMedium.Checked Then
    22.             frmMain.lstProducts.Items.Add("Bustle, Medium")
    23.         ElseIf radBustleLong.Checked Then
    24.             frmMain.lstProducts.Items.Add("Bustle, Long")
    25.  
    26.             CalculatePlan()
    27.         End If
    28.  
    29.         If radSteamSimple.Checked Then
    30.             frmMain.lstProducts.Items.Add("Steam Gown, Simple")
    31.         ElseIf radSteamingMultipleLayers.Checked Then
    32.             frmMain.lstProducts.Items.Add("Steam Gown, Multiple Layers")
    33.         ElseIf radSteamingComplex.Checked Then
    34.             frmMain.lstProducts.Items.Add("Steam Gown, Complex")
    35.  
    36.             CalculatePlan()
    37.         End If
    38.  
    39.         If IsNumeric(txtAdditionalCosts.Text) = True Then
    40.             frmMain.lstProducts.Items.Add(txtAdditionalCosts.Text)
    41.             ' frmMain.lstProducts.Items.Add("Additional Costs")
    42.             'frmMain.lblSubtotal.it(txtAdditionalCosts.Text)
    43.         End If
    44.        
    45.     End Sub  
    46.  
    47.     Function OtherCharges() As Decimal
    48.         Dim decCostOfOther As Decimal = 0
    49.         Dim intAlterations As Decimal = 0
    50.  
    51.         If IsNumeric(txtAdditionalCosts.Text) = True Then
    52.             decCostOfOther = (CDec(txtAdditionalCosts.Text))
    53.         ElseIf IsNumeric(txtAdditionalCosts.Text) = False Then
    54.             decCostOfOther = 0
    55.             CalculatePlan()
    56.         End If
    57.  
    58.         Return decCostOfOther
    59.  
    60.         CalculatePlan()
    61.      
    62.         End Function
    63.  
    64.     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    65.         Me.Close()
    66.     End Sub
    67. End Class
    Here is the Module I created a new variable "decAlt" to try this process.
    vb.net Code:
    1. Module BridalBoutiqueModule
    2.     Const decTAX_RATE As Decimal = 0.06D    ' Tax rate.
    3.  
    4.     Public Sub CalculatePlan()
    5.  
    6.         ' Declare variables used in the calculation
    7.         Dim decSubtotal As Decimal = 0
    8.         Dim decTax As Decimal = 0
    9.         Dim decTotal As Decimal = 0
    10.         Dim decAmntDueToday As Decimal = 0
    11.         Dim decDiscountRate As Decimal = 0
    12.         Dim decDiscount As Decimal = 0
    13.         Dim decDiscountRates As Decimal = 0
    14.         '  Dim decOther As Decimal = 0
    15.         Dim dtmSystemDate As Date = Now
    16.         dtmSystemDate = dtmSystemDate.AddDays(60)
    17.  
    18.         ' Calculate the subtotal and shipping by
    19.         ' going over the items in the shopping cart and
    20.         ' adding their values.
    21.         Dim intCount As Integer
    22.         For intCount = 0 To (frmMain.lstProducts.Items.Count - 1)
    23.             Select frmMain.lstProducts.Items(intCount).ToString()
    24.                 Case "Alyce Style: 7128 Price: $1807.00"
    25.                     decSubtotal += 1807D
    26.                 Case "Alyce Style: 7131 Price: $907.00"
    27.                     decSubtotal += 907D
    28.                 Case "Alyce Style: 7132 Price: $777.00"
    29.                     decSubtotal += 777D
    30.                 Case "Alyce Style: 7135 Price: $1297.00"
    31.                     decSubtotal += 1297D
    32.                 Case "Alyce Style: 7141 Price: $1207.00"
    33.                     decSubtotal += 1207D
    34.                 Case "Bari Jay Style: 2011 Price: $260.00"
    35.                     decSubtotal += 260D
    36.                 Case "Bari Jay Style: 69934 Price: $578.00"
    37.                     decSubtotal += 578D
    38.                 Case "Bari Jay Style: 69936 Price: $460.00"
    39.                     decSubtotal += 460D
    40.                 Case "Bari Jay Style: 69941 Price: $330.00"
    41.                     decSubtotal += 330D
    42.                 Case "Cassablanca Style: 1994 Price: $1700.00"
    43.                     decSubtotal += 1700D
    44.                 Case "Cassablanca Style: 1995 Price: $1463.00"
    45.                     decSubtotal += 1463D
    46.                 Case "Cassablanca Style: 1998 Price: $1287.00"
    47.                     decSubtotal += 1287D
    48.                 Case "Cassablanca Style: 2000 Price: $1229.00"
    49.                     decSubtotal += 1299D
    50.                 Case "Cassablanca Style: 2003 Price: $995.00"
    51.                     decSubtotal += 995D
    52.                 Case "Davinci Style: 8435 Price: $949.00"
    53.                     decSubtotal += 949D
    54.                 Case "Davinci Style: 8439 Price: $507.00"
    55.                     decSubtotal += 507D
    56.                 Case "Davinci Style: 8442 Price: $837.00"
    57.                     decSubtotal += 837D
    58.                 Case "Davinci Style: 8445 Price: $629.00"
    59.                     decSubtotal += 629D
    60.                 Case "Hem, Simple"
    61.                     decSubtotal += 80D
    62.                 Case "Hem, Multiple Layers"
    63.                     decSubtotal += 120D
    64.                 Case "Hem, Complex"
    65.                     decSubtotal += 200D
    66.                 Case "Bustle, Short"
    67.                     decSubtotal += 30D
    68.                 Case "Bustle, Medium"
    69.                     decSubtotal += 60D
    70.                 Case "Bustle, Long"
    71.                     decSubtotal += 85D
    72.                 Case "Steam Gown, Simple"
    73.                     decSubtotal += 35D
    74.                 Case "Steam Gown, Multiple Layers"
    75.                     decSubtotal += 55D
    76.                 Case "Steam Gown, Complex"
    77.                     decSubtotal += 80D
    78.                 Case "Dessy Style: 2796 Price: $306.00"
    79.                     decSubtotal += 306D
    80.                 Case "Dessy Style: 2805 Price: $286.00"
    81.                     decSubtotal += 286D
    82.                 Case "Dessy Style: 2806 Price: $351.00"
    83.                     decSubtotal += 351D
    84.                 Case "Dessy Style: 2801 Price: $309.00"
    85.                     decSubtotal += 309D
    86.                 Case "Dessy Style: 2805 Price: $286.00"
    87.                     decSubtotal += 286D
    88.                 Case "Dessy Style: 2806 Price: $351.00"
    89.                     decSubtotal += 351D
    90.                 Case "Dessy Style: 2804 Price: $257.00"
    91.                     decSubtotal += 257D
    92.                 Case "Dessy Style: 2805 Price: $286.00"
    93.                     decSubtotal += 286D
    94.                 Case "Dessy Style: 2806 Price: $351.00"
    95.                     decSubtotal += 351D
    96.                 Case "Dessy Style: 2811 Price: $299.00"
    97.                     decSubtotal += 299D
    98.                 Case "Dessy Style: 2812 Price: $299.00"
    99.                     decSubtotal += 299D
    100.                 Case "Dessy Style: 2813 Price: $273.00"
    101.                     decSubtotal += 273D
    102.            
    103.             End Select
    104.         Next intCount
    105.  
    106.         If decSubtotal > 1800D Then
    107.             decDiscountRate = 0.1
    108.         End If
    109.              
    110.         Dim decAlt As Decimal
    111.         'decAlt = frmAlterations.OtherCharges()  
    112.  
    113.         ' Calculate tax and total.
    114.         decTax = decSubtotal * decTAX_RATE
    115.         decTotal = decSubtotal + decTax + decAlt
    116.  
    117.         decAmntDueToday = decTotal / 2
    118.         decDiscount = decDiscountRate * decSubtotal
    119.  
    120.         With frmMain
    121.  
    122.             .lblSubtotal.Text = decSubtotal.ToString("c")
    123.             .lblTax.Text = decTax.ToString("c")
    124.             .lblTotal.Text = decTotal.ToString("c")
    125.             .lblNextPayment.Text = dtmSystemDate.ToString("d")
    126.             .lblAmountDueToday.Text = decAmntDueToday.ToString("c")
    127.             .lblDiscount.Text = decDiscount.ToString("c")
    128.         End With
    129.  
    130.     End Sub
    131. End Module

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Help with Code

    Care to share what this is supposed to do? It seems to me that this is some kind of a 'shopping cart' which uses some list of merchandise and calculates the total cost of an order.
    The one thing I do not understand is why all prices and items are hardcoded? Isn't that inconvinient? Moreover, you store prices and products separately which in real life would cause a mess of things. People use databases for that or at least some external storage (text files) to store the data.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Re: Help with Code

    Yes, this is a shopping cart. The prices for specific items is defined however my problem is when I am trying to take text input from the "frmAlterations" for additional non specified costs I get errors or simply cannot get it to work. That is what I am having the issue with. This is an assignment for an additional class I am taking, an intro course to VB.

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