Author Message

I am trying to do some cumulative addition of some numbers that is very easy
to do in a spreadsheet, but I am having difficulty doing it with the grid
control.

For example - I have a bunch of data in ColumnA and for columnB I want to do
the cumulative summation

ColumnA                 ColumnB

10                              10
10                              20
5                                25
10                              35

so the formula is B1= A1 (only true for B1)

For all other values in ColumnB the formula is for example

B2 = A2+B1
B3 = A3+B2
B4 = A4 +B3
.
.
.
Bn = An +B(n-1)

Thanks for any help

Don

Thu, 21 Jan 1999 03:00:00 GMT

Quote:
>I am trying to do some cumulative addition of some numbers
>so the formula is B1= A1 (only true for B1)
>For all other values in ColumnB the formula is for example
>Bn = An +B(n-1)

Then do it like this:

For i% = Grid.FixedRows To Grid.Rows - 1 ' We start on .FixedRows to
' exclude fixed rows from
' processing

Grid.Row = i%
Grid.Col = Grid.FixedCols

' Since OldB = 0 when we're at the first row, both formulas are used.

A = Val(Grid.Text)
B = A + OldB
OldB = B

Grid.Col = Grid.FixedCols + 1
Grid.Text = CStr(B)

Next i%

--
Sex isn't the answer. Sex is the question. Yes! is the answer

Fri, 22 Jan 1999 03:00:00 GMT

Quote:

> >I am trying to do some cumulative addition of some numbers

> >so the formula is B1= A1 (only true for B1)

> >For all other values in ColumnB the formula is for example

> >Bn = An +B(n-1)

> Then do it like this:

> For i% = Grid.FixedRows To Grid.Rows - 1 ' We start on .FixedRows to
>                                          ' exclude fixed rows from
>                                          ' processing

>    Grid.Row = i%
>    Grid.Col = Grid.FixedCols

>    ' Since OldB = 0 when we're at the first row, both formulas are used.

>    A = Val(Grid.Text)
>    B = A + OldB
>    OldB = B

>    Grid.Col = Grid.FixedCols + 1
>    Grid.Text = CStr(B)

> Next i%

> --
> Sex isn't the answer. Sex is the question. Yes! is the answer

First of all, for future reference please post VB queries in the Visual
Basic groups.

Secondly, why are you using so many variables when you could just do
this:

Dim FinalValue%         'Are you sure this is an integer?
For i%=1 to Grid.FixedRows
Grid.Row=i%
FinalValue%=FinalValue%+Val(Grid.Text)
Next i%

Or, I'm sure you could use the formula property or something like that.

--

secret face of God."                  |  http://www.nauticom.net/~jfarr
- G. K. Chesterton    |  Dept. of Redundancy Dept.

Fri, 22 Jan 1999 03:00:00 GMT

Quote:
>First of all, for future reference please post VB queries in the Visual
>Basic groups.

Sorry, didn't see the Newsgroup header.

Quote:
>Secondly, why are you using so many variables when you could just do
>this:

'Cause "that" won't do the job. Besides, I was trying to teach the guy
something, not write fast and efficient code.

--
I rocked my baby sister all day.
Until I ran out of rocks.

Tue, 26 Jan 1999 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages