Cumulative Addition using GRID Control 
Author Message
 Cumulative Addition using GRID Control

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  
 Cumulative Addition using GRID Control


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  
 Cumulative Addition using GRID Control

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  
 Cumulative Addition using GRID Control


Please don't mail AND post.

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  
 
 [ 4 post ] 

 Relevant Pages 

1. Cumulative Addition using GRID Control

2. Dynamic addition of data grids and data controls

3. Porting a GRID code using GRID object from VB3 to VB6 using MSGRID

4. Porting a GRID code using GRID object from VB3 to VB6 using MSGRID

5. Forecasting using Grid and Graph Controls using VB4.0 16bit

6. Forecasting using Grid Control and Graph Control - VB4.0 16 bit

7. Using calendar control on a Grid control?

8. Run-time addition of controls

9. handling events in dynamic control addition

10. VB Control addition at runtime

11. DirectSS run-time control addition

12. Faster addition of items on a ListView Control

 

 
Powered by phpBB® Forum Software