Running Totals

Morn

Active member
Joined
Dec 4, 2006
Messages
40
Programming Experience
Beginner
I am trying to get some values that have been stored in variables to add togeather.

I have a form that calculates a total for the person before adding their personal details to a access DB.

The total for the person is added to the grand total and the form is reset (not reloaded), then the process begins again and we get a new total for person.

The bit that I can not get to work is the adding of both totals together, what I need is:

Grand total + person total = new grand total

What I get is:

Grand total + person total = person total

The code is below,

Any ideas?

VB.NET:
 Dim runningtotalofbooking As Decimal
        Dim holidaycost As Decimal
        Dim activitycost As Decimal
        Dim totaloftraveler As Decimal

 totaloftraveler = holidaycost + activitycost

        MsgBox("Traveler Cost: £ " & totaloftraveler)

        runningtotalofbooking = totaloftraveler + runningtotalofbooking

        MsgBox("Running Cost: £ " & runningtotalofbooking)
 
Did you defined the variable runningtotalofbooking before your loop? You can also use the += on runningtotal instead of typing the variable twice with a + sign. (ie: runningtotalofbooking += totaloftraveler)

VB.NET:
Dim runningtotalofbooking as Decimal

Do until (some condition)        
        Dim runningtotalofbooking As Decimal
        Dim holidaycost As Decimal
        Dim activitycost As Decimal
        Dim totaloftraveler As Decimal

        totaloftraveler = holidaycost + activitycost

        MsgBox("Traveler Cost: £ " & totaloftraveler)

        runningtotalofbooking += totaloftraveler

        MsgBox("Running Cost: £ " & runningtotalofbooking)
Loop
 
Thanks for that, figured it out straight after I clicked the submit button.

I mover the running total variable to the top of the form and then it just worked.

Thanks again
 
Back
Top