How to perform addition on each of the rows and columns and diagonally of the arra

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gparl
    New Member
    • May 2012
    • 1

    How to perform addition on each of the rows and columns and diagonally of the arra

    The Random generator works fine. What I have a problem with is adding the rows and columns.
    Array
    0,0 0,1 0,2 = row total
    1,0 1,1 1,2 = row total
    2,0 2,1 2,2 = row total
    = = =
    col total coltotal col total
    also add 0,0 1,1 2,2

    Code:
    Private Sub BtnFillArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFillArray.Click
    
            Dim Row As Integer
            Dim Col As Integer
            Dim Number As Integer
    
            Number = RandomNumber.Next(RandomNumberLimit)
            For Row = 0 To 2
                For Col = 0 To 2
                    TwoDim(Row, Col) = Number
                    
                    Number += 1
                Next Col
            Next Row
    
            Lbl3x3ArrCell00.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell01.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell02.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell10.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell11.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell12.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell20.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell21.Text = CStr(RandomNumber.Next(RandomNumberLimit))
            Lbl3x3ArrCell22.Text = CStr(RandomNumber.Next(RandomNumberLimit))
        LblGBRowR1r0.Text = ""   (holds results of 0,0 0,1 0,2)
        LblGBRowR1r1.Text = ""   (holds results of 1,0 1,1 1,2)
        LblGBRowR1r2.Text = ""   (holds results of 2,0 2,1 2,2)
        
        LblGBColC1c0.Text = ""   (holds results of 0,0 1,0 2,0)
        LblGBColC1c1.Text = ""   (holds results of 0,1 1,1 2,1)
        LblGBColC1c2.Text = ""   (holds results of 0,2 2,1 2,2)
        
        LblGBDiaL.Text = ""      (holds results of 0,0 1,1 2,2)
        LblGBDiaR.Text = ""      (holds results of 02 1,1 2,0)
     End Sub
    
    Tried this but results were faulty
      Private Sub BtnCF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCF.Click
    'LblGBRowR1r0.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(0, 1) + TwoDim(0, 0)))))
        'LblGBRowR1r1.Text = Convert.ToString(CInt(((TwoDim(1, 0) + TwoDim(1, 1) + TwoDim(1, 2)))))
        'LblGBRowR1r2.Text = Convert.ToString(CInt(((TwoDim(2, 0) + TwoDim(2, 1) + TwoDim(2, 2)))))
        'LblGBColC1c0.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 0) + TwoDim(2, 0)))))
        'LblGBColC1c1.Text = Convert.ToString(CInt(((TwoDim(0, 1) + TwoDim(1, 1) + TwoDim(2, 1)))))
        'LblGBColC1c2.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(1, 2) + TwoDim(2, 2)))))
        'LblGBDiaL.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 1) + TwoDim(2, 2)))))
        'LblGBDiaR.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(1, 1) + TwoDim(2, 0)))))
        'End Sub
    Just need a simple method to add Thanks
    Last edited by PsychoCoder; May 24 '12, 11:26 PM. Reason: Code tags added
Working...