#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0

    Sub Routine in a Function


    I am trying to program a promo code to give a 5% discount to customers entering the code. My problem is that it is within a shopping cart that is already a part of a larger function. Whenever I try to program my subroutine it errors out saying that you cannot have a sub within a method.
    What can I do?
  2. #2
  3. I do .NET for a living
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Sep 2003
    Location
    Florida
    Posts
    1,549
    Rep Power
    211
    Put the new sub outside the method (sub or function) you need to call if from.

    You probably have something like:
    Code:
    Public Class Cart
      Private Sub ShoppingCart()
         ...code
      End Sub
    End Class
    and you're probably trying to put your new sub or function within that. It needs to be outside:
    Code:
    Public Class Cart
      Private Sub ShoppingCart()
         ...code
      End Sub
      Private Sub CalculateDiscount()
        ...code
      End Sub
    End Class
    Roger (.NET MCP)
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    This is what I actually have for getting the totals in the Checkout box:

    Function GetItemTotal() As Decimal

    Dim decRunningTotal As Decimal

    If Not objDT is Nothing Then
    For Each objDR In objDT.Rows
    decRunningTotal += (objDR("Item Total"))
    Next
    Else
    decRunningTotal = "0.00"
    End If

    Return decRunningTotal

    End Function


    I have created the following comparator to check for the promo code:

    <asp:CompareValidator runat="server" ErrorMessage="" id="CompareValidator1" ControlToValidate="TextBoxPromo" ValueToCompare="BNOV12">
    </asp:CompareValidator>
    <asp:TextBox runat="server" id="TextBoxPromo"></asp:TextBox>

    Now how do I change the function to tell it that if CompareValidator1 is correct to give a 5% dicaount on decRunningTotal?

    Thanks,


    Dave
  6. #4
  7. I do .NET for a living
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Sep 2003
    Location
    Florida
    Posts
    1,549
    Rep Power
    211
    Why use a CompareValidator for that? Why not just check the contents of the textbox when they hit submit and make the call to apply the discount? If you need it to show before they submit, then create a textchanged event handler for the promo textbox and if the entered text is your code, call the discount function and update your displayed total.

Similar Threads

  1. Replies: 1
    Last Post: October 21st, 2009, 08:52 AM
  2. DB Connection in Function/Sub Routine
    By z1ppy in forum ASP Development
    Replies: 3
    Last Post: December 8th, 2006, 09:17 AM
  3. Help with ASP routine!!
    By discus364 in forum HTML, JavaScript And CSS Help
    Replies: 6
    Last Post: May 30th, 2006, 03:28 AM
  4. Cancel Sub Routine
    By Exodus in forum Microsoft Access Help
    Replies: 8
    Last Post: August 12th, 2004, 05:09 PM
  5. executing a sub routine
    By Steve Schofield in forum ASP Development
    Replies: 1
    Last Post: August 23rd, 2000, 09:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo