Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51 03' -78" N -114 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Needing Assistance In Shortning Some Code

    I was wondering if anyone could help me with the following code would get way to long if I kept going this route I am sure there is a mathimatical way of making this work!
    What I am trying to do is when someone enters a number there will be a value that goes with that number the value works on the following chart

    -----------------------------------------
    Pictures = 3.99
    3Pictures = 9.99
    10Pictures = 19.99
    -----------------------------------------
    here is the code below

    Code:
    Dim PicTotal
    IF Request.Form("Muploadlimit") = "1" Then PicTotal = RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "2" Then PicTotal = (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "3" Then PicTotal = RSE.Fields("3Pictures")
    IF Request.Form("Muploadlimit") = "4" Then PicTotal = RSE.Fields("3Pictures") + RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "5" Then PicTotal = RSE.Fields("3Pictures") + (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "6" Then PicTotal = (RSE.Fields("3Pictures")*2)
    IF Request.Form("Muploadlimit") = "7" Then PicTotal = (RSE.Fields("3Pictures")*2) + RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "8" Then PicTotal = (RSE.Fields("3Pictures")*2) + (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "9" Then PicTotal = (RSE.Fields("3Pictures")*3)
    IF Request.Form("Muploadlimit") = "10" Then PicTotal = RSE.Fields("10Pictures")
    IF Request.Form("Muploadlimit") = "11" Then PicTotal = RSE.Fields("10Pictures") + RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "12" Then PicTotal = RSE.Fields("10Pictures") + (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "13" Then PicTotal = RSE.Fields("10Pictures") + RSE.Fields("3Pictures")
    IF Request.Form("Muploadlimit") = "14" Then PicTotal = RSE.Fields("10Pictures") + RSE.Fields("3Pictures") + RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "15" Then PicTotal = RSE.Fields("10Pictures") + RSE.Fields("3Pictures") + (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "16" Then PicTotal = RSE.Fields("10Pictures") + (RSE.Fields("3Pictures")*2)
    IF Request.Form("Muploadlimit") = "17" Then PicTotal = RSE.Fields("10Pictures") + (RSE.Fields("3Pictures")*2) + RSE.Fields("Pictures")
    IF Request.Form("Muploadlimit") = "18" Then PicTotal = RSE.Fields("10Pictures") + (RSE.Fields("3Pictures")*2) + (RSE.Fields("Pictures")*2)
    IF Request.Form("Muploadlimit") = "19" Then PicTotal = RSE.Fields("10Pictures") + (RSE.Fields("3Pictures")*3)
    IF Request.Form("Muploadlimit") = "20" Then PicTotal = (RSE.Fields("10Pictures")*2)
    IF Request.Form("Muploadlimit") = "21" Then PicTotal = (RSE.Fields("10Pictures")*2) + RSE.Fields("Pictures")
    Response.Write " @ $"&PicTotal
    SubTotal = SubTotal + PicTotal

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You could do a Select Case so that it only has to retrieve the value from the Request.Form() collection once. It may speed it up (not that you'd notice...) but I dunno how much shorter it could be.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51 03' -78" N -114 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess what I am lookiong for is a math equation that would work for any number where X = y or something

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Apart from the fact that that's a *crazy* pricing system (e.g. 9 units = 29.97, whereas 10 are 19.99), here's what I've cooked up for you:
    Code:
    Function GetCost(Num)
      Dim Remainder
    
      GetCost = (Num \ 10) * 19.99
      Remainder = Num MOD 10
    
      GetCost = GetCost + ((Remainder \ 3) * 9.99)
      Remainder = Remainder MOD 3
    
      GetCost = GetCost + (Remainder * 3.99)
    End Function
    Output:
    GetCost(1) = 3.99
    GetCost(2) = 7.98
    GetCost(3) = 9.99
    GetCost(4) = 13.98
    GetCost(5) = 17.97
    GetCost(6) = 19.98
    GetCost(7) = 23.97
    GetCost(8) = 27.96
    GetCost(9) = 29.97
    GetCost(10) = 19.99
    GetCost(11) = 23.98
    GetCost(12) = 27.97
    GetCost(13) = 29.98
    GetCost(14) = 33.97
    GetCost(15) = 37.96
    GetCost(16) = 39.97
    GetCost(17) = 43.96
    GetCost(18) = 47.95
    GetCost(19) = 49.96
    GetCost(20) = 39.98
    GetCost(21) = 43.97
    It should go without saying (but I'll say it anyway) that I present this code on the assumption that you will spend time understanding the code and brushing up on your VBScript operators so that you could do it yourself next time...

    Last edited by M@rco; 11-05-2003 at 12:33 AM.
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    51 03' -78" N -114 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Of course! I was trying to give people a deal so that if they where to buy more they get a better deal! But I do see what you mean by really wiered pricing! Any thoughts people?

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Why not simply offer a compound discount (like compound interest)?

    Something like this:
    Cost = (Units * BaseRate) * (0.99^Units)

    The exact value will need tweaking...
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"


  •  

    Posting Permissions

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