Announcement

Collapse
No announcement yet.

Simple Addition isn't Working.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Addition isn't Working.

    I've got some code that I've been using for quite a bit of time, to generate a report from VoIP Call Detail Records. Recently, I decided that I needed to make some changes to the code and now I have a problem that I just can't figure out. And this is a simple problem.

    Here the part of the code that isn't working properly. This code is in a Sub program. All of the variables, including the Type variables are all Global.

    I inserted some MSGBOXs to look at the values of the variables to try to see what's happening. I took those MSGBOXs to show the code here.

    As an example, when this program runs, Temp11# will show as a value of 49.xxxxxxxxxxxx (I don't remember the exact number). Temp12# will show as a value of 12.94xxxxxxxxxxx.

    Temp13# will show as 0.

    These values are correct, based on the data that has been put into the program, earlier in the code.

    But, Temp14#, which should be the sum of the three above values (around 22.37xxxxxxxxx or thereabouts), shows a value of 0. The three values are not being added together.

    FederalUSFRate# shows a value of .318 (which is correct). And Temp15# also shows 0, which of course would be correct since Temp14# is 0.

    I have tried several different things, include changing data types (SINGLE to DOUBLE). And I've tried using the Type variables instead of the Temp variables. Nothing works.

    Any ideas?

    John Rayfield, Jr.



    SUB ProgramName

    Temp11# = 0
    Temp12# = 0
    Temp13# = 0
    Temp14# = 0
    Temp15# = 0

    FOR CustomerCounter& = 1 TO MaxCustomer&

    Temp11# = (CustomerData(CustomerCounter&).TotalInterstateCost)
    Temp12# = (CustomerData(CustomerCounter&).TotalDIDRecurring * CustomerData(CustomerCounter&).ORIGInterRevenuePercent)
    Temp13# = (CustomerData(CustomerCounter&).TotalDID800Recurring * CustomerData(CustomerCounter&).Orig800InterRevenuePercent)

    Temp14# = Temp11# + Temp12# + Temp13#
    Temp15# = Temp14# * FederalUSFRate#

    CustomerData(CustomerCounter&).FederalUSF = Temp15#
    TotalFederalUSF# = TotalFederalUSF# + CustomerData(CustomerCounter&).FederalUSF

    NEXT CustomerCounter&

    END SUB


  • #2
    The problem may be the use of MSGBOX. Try using a TXT.WINDOW to output the values.
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      What does ERR say?
      "Not my circus, not my monkeys."

      Comment


      • #4
        What changes? If the changes is the cause, it should be easy to trace backwards to find problem. Cause could be elsewhere too, and / or arrays out of bounds, etc. #DEBUG ERROR ON can help if that's the case.

        > needed to make some changes to the code and now I have a problem

        Comment


        • #5
          First of all, I tried this:

          Temp14# = Temp11# + Temp12#

          Just adding the two values together. It worked fine.

          Then I tried this:

          Temp14# = Temp11# + Temp12#
          Temp14# = Temp14# + Temp13#

          And Temp14# now showed a value of 0.

          When I add the variable that has a value of 0, the value of Temp14# is set to 0.

          I remarked out the MSGBOXs and the report that the program generates has the wrong values (0 instead of the correct value). The report does generate the correct values, but ONLY if Temp13# in the above code has a value other than 0.

          So we're back to the simple formula of:

          Temp14$ = Temp11# + Temp12# + Temp13#

          Not working if Temp13# has a value of 0.

          I do have some large arrays. So, for one of them that I don't need after using it for part of the program, and before I enter the above code, I ERASEd it, like this: ERASE VI_CDR_Array(). This array does have TYPE members. Is this the correct way to release the memory that this array was using?

          John



          Comment


          • #6
            Yes, erase. Are you sure there's no overflow or div by 0 (can cause nasty "hanging" errors that may crash later in flow) or even a silly fault like having managed to type multiplication mark instead of plus sign somewhere (I once did that in a large code and it took a while to find out why I got 0-results later on in flow - part result could become multiplied with 0..).

            Comment


            • #7
              . . . or even a silly fault like having managed to type multiplication mark instead of plus sign . . .
              ditto! An accidental times zero somewhere. Or, a fraction (less than one) to an integer, gets truncated to zero, then multiplied.

              Cheers,
              Dale

              Comment


              • #8
                Use the search feature to find all instances of Temp13# and check each term in any equations you find.
                #DEBUG ERROR ON as previously suggested and a sprinkling of labels might lead you to it.
                Rod
                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                Comment


                • #9
                  SInce we don't know how you have defined the elements of the UDT that CustomerData is based on, it's hard to say what may be going wrong.

                  Do you have #DIM ALL, #DEBUG DISPLAY ON and #DEBUG ERROR ON ?

                  Comment


                  • #10
                    Originally posted by John Rayfield Jr View Post
                    As an example, when this program runs, Temp11# will show as a value of 49.xxxxxxxxxxxx (I don't remember the exact number). Temp12# will show as a value of 12.94xxxxxxxxxxx.

                    Temp13# will show as 0.

                    These values are correct, based on the data that has been put into the program, earlier in the code.

                    But, Temp14#, which should be the sum of the three above values (around 22.37xxxxxxxxx or thereabouts), shows a value of 0.
                    49.x + 12.94x + 0 is more like 61.94 than 22.37


                    Comment


                    • #11
                      What do you get with:
                      Code:
                      Temp14# = (CustomerData(CustomerCounter&).TotalInterstateCost) + _
                          (CustomerData(CustomerCounter&).TotalDIDRecurring * CustomerData(CustomerCounter&).ORIGInterRevenuePercent) + _
                          (CustomerData(CustomerCounter&).TotalDID800Recurring * CustomerData(CustomerCounter&).Orig800InterRevenuePercent)

                      Comment


                      • #12
                        My bad, It should be : #DEBUG DISPLAY ON and a sprinkling of labels might lead you to it.
                        Rod
                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                        Comment


                        • #13
                          Math errors are usually easy to find in debug mode. Compile with debug and set all important variables to watch then step through the code line by line until something doesn't add up.

                          Comment

                          Working...
                          X