Add cells in a datagrid

I have a datagrid in vb6.  I have columns 10 through 35 that should have numbers in them.  From the datagrid I want them to autoTotal into column 36.  Is there a way to do this.  Its kind of simalar to what Microsoft Excel does with the SUM function.
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wellholeCommented:
Add a column to your datasource, then loop through it and run a sum and put the result into the column you added.

table.Columns.Add("mysum")

for each row in table
  for i = 10 to 35
    table("mysum") += row(i)
  next
next
0
al4629740Author Commented:
Is that code for vb6?  The following line does not work

table("Total") += row(i)
0
wellholeCommented:
oops...

row("mysum") += row(i)
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

al4629740Author Commented:
Still no go..
0
wellholeCommented:
And your problem is.......?
0
al4629740Author Commented:
Meaning your formula does not work.  Will this work?

For Each Row In Table
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next
0
wellholeCommented:
You forgot Table.Rows in your first line.
0
al4629740Author Commented:
Could you show me what your talking about.  I am very novice to VB
0
wellholeCommented:
It would be very helpful if you provided the error messages instead of just saying "it doesn't work".
0
al4629740Author Commented:
Ok, originally you sent the code and it showed Expected:expression   Compile error on this line

table("mysum") += row(i)
0
wellholeCommented:
Right. Now that you have the code below, what errors do you have now?

For Each Row In Table.Rows
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next
0
al4629740Author Commented:
Object required in the first line

For Each Row In Table.Rows
0
wellholeCommented:
al, is your table variable called Table?
0
al4629740Author Commented:
ha, good catch.  I changed it to the following:

For Each Row In DataGrid1.Row
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next

But I still get an error on the first line:

Compile error:
For Each may only iterate over a collection object or array

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wellholeCommented:
al, is your datagrid binding to a table or are you adding into the grid programmatically?
0
al4629740Author Commented:
Programmatically, as follows:

      rec.CursorType = adOpenDynamic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText



     
        Set DataGrid1.DataSource = rec
0
al4629740Author Commented:
raised point value
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.