Need to display sum/average of rows and columns of global integer array

Lan Solo

Newcomer
Joined
May 28, 2003
Messages
15
Location
Alameda, CA
Ok, my verbiage might not be right on the money (cuz I'm a Newbie) but let me try to explain.

My school project requires that we declare a data table as a Global Integer Array. The form menu gives the user options to either sum or average the rows and columns and then display the results in a message box.

I am having trouble determining the subs or variables that will be used when the click event occurs. Here is some code from the project. If anyone has any suggestions or can see where I am messing up, that would be great. I can't seem to get the desired results to display.

Code:
Dim gintTable(,) = {{5, 7, 3, 9, 12}, {4, 8, 9, 13, 4}, {0, -1, -7, 13, 8}, {4, 4, 4, 4, 0}} 

    Dim intRowSum As Integer 

    Dim C As Integer 

    Dim R As Integer 

    Dim X As Integer 

    Dim IntSum 

    Dim strX As String 

    Dim ControlChar 

  

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

  

    End Sub 

  

    Private Sub btnRowSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRowSum.Click 

        For R = 0 To 3 

            For X = 1 To 4 

                For C = 0 To 4 

                    IntSum += gintTable(R, C) 

                Next C 

                strX = IntSum 

            Next X 

        Next R 

    End Sub

R is for Row, C is for Column, X is the incremental variable I want to 'attach' to str, so each loop will generate a new total.

So - One thing I cannot get it to do, my 'strX' is the 'Result' and the logic is failing.

How do I get ‘strX’ to 'hold' it's value each loop, and display in the MsgBox, noncumulative?

(I wanted X to increase by 1 each loop and end up with 'str1, str2... or strX1, strX2...)

Thanks in advance.
 
VolteFace said:
& and &= are the string appending operators.

Maybe for VB, but for C# you use + for string concatenation. Maybe you can use both & and + in C#, but I know for a fact you can use +=.
 
Oh, heh, yeah. I thought you meant VB in comparison to C#, not
other way around.

If you're going to be doing any significant amount of string building,
you should use the StringBuilder class (with it's .Append method)
anyway. :p
 
Back
Top