ABeer4Me Posted May 26, 2005 Posted May 26, 2005 (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 May 26, 2005 by PlausiblyDamp Quote
ABeer4Me Posted May 26, 2005 Author Posted May 26, 2005 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 Quote
geissingert Posted May 26, 2005 Posted May 26, 2005 ' 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, , ) Quote
ABeer4Me Posted May 26, 2005 Author Posted May 26, 2005 Thanks that works! Thanks that code answers the question I had. I really appreciate it. :) :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.