Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Sub Routine in a Function

Results 1 to 3 of 3
Share This Thread →
  1. #1
    captain15 is offline Registered User ASP Free Newbie (0 - 499 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
    rclark's Avatar
    rclark is offline I do .NET for a living ASP Free Intermediate (1500 - 1999 posts)
    Join Date
    Sep 2003
    Location
    Florida
    Posts
    1,538
    Rep Power
    209
    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)

  3. #3
    captain15 is offline Registered User ASP Free Newbie (0 - 499 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

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

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

ASP Free Advertisers and Affiliates