Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Function Problem

    Hi,

    I have the following function below used to make a couple
    of calculations however as soon as I have two records the
    function calculation is wrong.

    EG:
    Record 1:
    tmprs(0) = 1
    tmprs(1) = 100
    tmprs(2) = 20
    tmprs(3) = 25

    Record 2:
    tmprs(0) = 1
    tmprs(1) = 1000
    tmprs(2) = 10
    tmprs(3) = 25

    The function should return the value 1225 but I get the
    wrong result 1000

    Can someone please tell me why this might be occuring!

    Thanks

    ...:: CODE ::..

    function proctotal (procid)
    dim tmprs, sql, total

    total = 0
    sql = "Select s.Quantity, s.UnitCost, s.Disc, p.taxamt
    FROM tblSupply s LEFT JOIN tblPurchase p ON s.procid =
    p.procid WHERE p.procid = '" & procid & "';"
    set tmprs = server.createobject("adodb.recordset")
    tmprs.open sql, conn, 1, 2
    if tmprs.eof then
    total = 0
    else
    while not tmprs.eof
    total = total + ((tmprs(0)* tmprs(1)) / 100 * tmprs
    (2))
    total = (tmprs(0)*tmprs(1)) - total
    total = total + ((total / 100) * tmprs(3))
    tmprs.movenext

    wend
    end if
    proctotal = total
    end function

    MyaTiX Guest

  2. Similar Questions and Discussions

    1. Problem with function ListGetAt
      I have written the code for a DB driven image viewer. It is pretty simple. I am having a problem with my navagtion going to the previous and next...
    2. Problem using GD function
      Hi all, I've got a Red Hat 9 system with gd-1.8.4 installed and php-4.3.4 working on apache 2.0.48. When I try to use the imagecreatefromjpeg...
    3. problem with db function php
      hi echo '<table>'; $requete = mysql_query("SELECT liv_nolivre, sec_nosection, liv_commentaire, liv_titre FROM livre"); if (...
    4. Problem with split function
      Hi all, I am having a problem with the split function. Here is my code: $_ = "123 a 456 b 789 c"; my @words = split /+/, $_; print...
    5. [PHP] isset function problem
      What about the rest of the code? How is this variable defined? I have had this happen in some code before, I found that the variable was set to...
  3. #2

    Default Re: Function Problem

    "MyaTiX" <anonymous@discussions.microsoft.com> wrote in message
    news:05e201c3ce0b$af496210$a401280a@phx.gbl...
    > Hi,
    >
    > I have the following function below used to make a couple
    > of calculations however as soon as I have two records the
    > function calculation is wrong.
    >
    > EG:
    > Record 1:
    > tmprs(0) = 1
    > tmprs(1) = 100
    > tmprs(2) = 20
    > tmprs(3) = 25
    >
    > Record 2:
    > tmprs(0) = 1
    > tmprs(1) = 1000
    > tmprs(2) = 10
    > tmprs(3) = 25
    >
    > The function should return the value 1225 but I get the
    > wrong result 1000
    >
    > Can someone please tell me why this might be occuring!
    >
    > Thanks
    >
    > ..:: CODE ::..
    >
    > function proctotal (procid)
    > dim tmprs, sql, total
    >
    > total = 0
    > sql = "Select s.Quantity, s.UnitCost, s.Disc, p.taxamt
    > FROM tblSupply s LEFT JOIN tblPurchase p ON s.procid =
    > p.procid WHERE p.procid = '" & procid & "';"
    > set tmprs = server.createobject("adodb.recordset")
    > tmprs.open sql, conn, 1, 2
    > if tmprs.eof then
    > total = 0
    > else
    > while not tmprs.eof
    > total = total + ((tmprs(0)* tmprs(1)) / 100 * tmprs
    > (2))
    > total = (tmprs(0)*tmprs(1)) - total
    > total = total + ((total / 100) * tmprs(3))
    > tmprs.movenext
    >
    > wend
    > end if
    > proctotal = total
    > end function
    1000 seems correct; below are my intermediate calculations:

    total = 0

    total = total + (1 * 100) / 100 * 20
    0 + 100 / 100 * 20
    0 + 1 * 20
    20
    total = (1 * 100) - total
    100 - 20
    80
    total = total + ((total / 100) * 25)
    80 + (80 / 100) * 25
    80 + .8 * 25
    80 + 20
    100

    total = total + (1 * 1000) / 100 * 10
    100 + 1000 / 100 * 10
    100 + 10 * 10
    100 + 100
    200
    total = (1 * 1000) - total
    1000 - 200
    800
    total = total + ((total / 100) * 25)
    800 + (800 / 100) * 25
    800 + 8 * 25
    800 + 200
    1000



    McKirahan Guest

  4. #3

    Default Re: Function Problem

    Ya OK the calculation is correct but I don't want this
    response.

    I would like it to calculate record 1 first then record 2
    and add them together. This should also work if there are
    more than 2 records.

    I hope that this explains th eproblem a bit better!

    Thanks for the response.



    >-----Original Message-----
    >"MyaTiX" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:05e201c3ce0b$af496210$a401280a@phx.gbl...
    >> Hi,
    >>
    >> I have the following function below used to make a
    couple
    >> of calculations however as soon as I have two records
    the
    >> function calculation is wrong.
    >>
    >> EG:
    >> Record 1:
    >> tmprs(0) = 1
    >> tmprs(1) = 100
    >> tmprs(2) = 20
    >> tmprs(3) = 25
    >>
    >> Record 2:
    >> tmprs(0) = 1
    >> tmprs(1) = 1000
    >> tmprs(2) = 10
    >> tmprs(3) = 25
    >>
    >> The function should return the value 1225 but I get the
    >> wrong result 1000
    >>
    >> Can someone please tell me why this might be occuring!
    >>
    >> Thanks
    >>
    >> ..:: CODE ::..
    >>
    >> function proctotal (procid)
    >> dim tmprs, sql, total
    >>
    >> total = 0
    >> sql = "Select s.Quantity, s.UnitCost, s.Disc,
    p.taxamt
    >> FROM tblSupply s LEFT JOIN tblPurchase p ON s.procid =
    >> p.procid WHERE p.procid = '" & procid & "';"
    >> set tmprs = server.createobject("adodb.recordset")
    >> tmprs.open sql, conn, 1, 2
    >> if tmprs.eof then
    >> total = 0
    >> else
    >> while not tmprs.eof
    >> total = total + ((tmprs(0)* tmprs(1)) / 100 *
    tmprs
    >> (2))
    >> total = (tmprs(0)*tmprs(1)) - total
    >> total = total + ((total / 100) * tmprs(3))
    >> tmprs.movenext
    >>
    >> wend
    >> end if
    >> proctotal = total
    >> end function
    >
    >1000 seems correct; below are my intermediate
    calculations:
    >
    >total = 0
    >
    >total = total + (1 * 100) / 100 * 20
    > 0 + 100 / 100 * 20
    > 0 + 1 * 20
    > 20
    >total = (1 * 100) - total
    > 100 - 20
    > 80
    >total = total + ((total / 100) * 25)
    > 80 + (80 / 100) * 25
    > 80 + .8 * 25
    > 80 + 20
    > 100
    >
    >total = total + (1 * 1000) / 100 * 10
    > 100 + 1000 / 100 * 10
    > 100 + 10 * 10
    > 100 + 100
    > 200
    >total = (1 * 1000) - total
    > 1000 - 200
    > 800
    >total = total + ((total / 100) * 25)
    > 800 + (800 / 100) * 25
    > 800 + 8 * 25
    > 800 + 200
    > 1000
    >
    >
    >
    >.
    >
    MyaTiX Guest

  5. #4

    Default Re: Function Problem

    "MyaTiX" <anonymous@discussions.microsoft.com> wrote in message
    news:06e001c3ce19$694ffd60$a401280a@phx.gbl...
    > Ya OK the calculation is correct but I don't want this
    > response.
    >
    > I would like it to calculate record 1 first then record 2
    > and add them together. This should also work if there are
    > more than 2 records.
    >
    > I hope that this explains th eproblem a bit better!
    >
    > Thanks for the response.


    Use "subtotal" for each record then add it to "total".

    function proctotal (procid)
    proctotal = 0
    dim subtotal
    dim total
    total = 0
    dim sql
    sql = "SELECT s.Quantity, s.UnitCost, s.Disc, p.taxamt"
    sql = sql & " FROM tblSupply s"
    sql = sql & " LEFT JOIN tblPurchase p ON s.procid = p.procid"
    sql = sql & " WHERE p.procid = '" & procid & "';"
    dim tmprs
    set tmprs = server.createobject("adodb.recordset")
    tmprs.open sql, conn, 1, 2
    if not tmprs.eof then
    while not tmprs.eof
    subtotal = ((tmprs(0) * tmprs(1)) / 100 * tmprs(2))
    subtotal = (tmprs(0) * tmprs(1)) - subtotal
    subtotal = subtotal + ((subtotal / 100) * tmprs(3))
    tmprs.movenext
    total = total + subtotal
    wend
    end if
    proctotal = total
    end function


    I restructured your code for readability on my part.


    McKirahan Guest

  6. #5

    Default Re: Function Problem

    Oops, two lines should be switched to:

    total = total + subtotal
    tmprs.movenext

    Accumulate the total before moving to the next record.


    McKirahan Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139