Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted (edited)

Display Question

 

Edit: Split from This Thread

 

I'm having the same problem with this procedure. When I run the code I receive a total not an individual sum. Is there a different way to request the display? I'm currently using the following.

 

Dim MyArray2(,) As Integer = {{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 mnuSumCol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSumCol.Click

 

'This enables the user to use the Perform Action command

'menu item under the File menu

 

For R = 0 To 3

 

For X = 1 To 4

 

For C = 0 To 4

 

IntSum += MyArray2(R, C)

 

Next C

 

strX += IntSum

 

Next X

 

Next R

 

'This displays the sum of the column

MsgBox(IntSum, , )

 

mnuPerAct.Enabled = True

'This indicates that the Sum Column command on the Action menu

'has been selected

 

 

mnuSumRow.Checked = False

mnuSumCol.Checked = True

mnuAvgRow.Checked = False

mnuAvgCol.Checked = False

 

I'm new to VB and can use some assistance. Sorry about the wording I have been up most to the night working on this. Thanks

Edited by PlausiblyDamp
Posted

More explaination

 

I may not have explained it correctly, but this is what I'm trying to do. The column sum should show

13

18

9

41

24

 

The problem is it's showing a total not the sum for each column. I'm using a msgbox which could be wrong all together. I just need to know who to get the formula to display each row sum.

 

Thanks

Posted

' Try the following code:

 

Dim MyArray2(,) As Integer = {{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 As Double

Dim strX As String

Dim ControlChar

 

For C = 0 To MyArray2.GetUpperBound(1)

IntSum = 0

For R = 0 To MyArray2.GetUpperBound(0)

IntSum += MyArray2(R, C)

Next

strX &= IntSum.ToString() & vbCrLf

Next

 

'This displays the sum of the column

MsgBox(strX, , )

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...