By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

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

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. Private Sub BtnFillArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFillArray.Click
  2.  
  3.         Dim Row As Integer
  4.         Dim Col As Integer
  5.         Dim Number As Integer
  6.  
  7.         Number = RandomNumber.Next(RandomNumberLimit)
  8.         For Row = 0 To 2
  9.             For Col = 0 To 2
  10.                 TwoDim(Row, Col) = Number
  11.  
  12.                 Number += 1
  13.             Next Col
  14.         Next Row
  15.  
  16.         Lbl3x3ArrCell00.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  17.         Lbl3x3ArrCell01.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  18.         Lbl3x3ArrCell02.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  19.         Lbl3x3ArrCell10.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  20.         Lbl3x3ArrCell11.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  21.         Lbl3x3ArrCell12.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  22.         Lbl3x3ArrCell20.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  23.         Lbl3x3ArrCell21.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  24.         Lbl3x3ArrCell22.Text = CStr(RandomNumber.Next(RandomNumberLimit))
  25.     LblGBRowR1r0.Text = ""   (holds results of 0,0 0,1 0,2)
  26.     LblGBRowR1r1.Text = ""   (holds results of 1,0 1,1 1,2)
  27.     LblGBRowR1r2.Text = ""   (holds results of 2,0 2,1 2,2)
  28.  
  29.     LblGBColC1c0.Text = ""   (holds results of 0,0 1,0 2,0)
  30.     LblGBColC1c1.Text = ""   (holds results of 0,1 1,1 2,1)
  31.     LblGBColC1c2.Text = ""   (holds results of 0,2 2,1 2,2)
  32.  
  33.     LblGBDiaL.Text = ""      (holds results of 0,0 1,1 2,2)
  34.     LblGBDiaR.Text = ""      (holds results of 02 1,1 2,0)
  35.  End Sub
  36.  
  37. Tried this but results were faulty
  38.   Private Sub BtnCF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCF.Click
  39. 'LblGBRowR1r0.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(0, 1) + TwoDim(0, 0)))))
  40.     'LblGBRowR1r1.Text = Convert.ToString(CInt(((TwoDim(1, 0) + TwoDim(1, 1) + TwoDim(1, 2)))))
  41.     'LblGBRowR1r2.Text = Convert.ToString(CInt(((TwoDim(2, 0) + TwoDim(2, 1) + TwoDim(2, 2)))))
  42.     'LblGBColC1c0.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 0) + TwoDim(2, 0)))))
  43.     'LblGBColC1c1.Text = Convert.ToString(CInt(((TwoDim(0, 1) + TwoDim(1, 1) + TwoDim(2, 1)))))
  44.     'LblGBColC1c2.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(1, 2) + TwoDim(2, 2)))))
  45.     'LblGBDiaL.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 1) + TwoDim(2, 2)))))
  46.     'LblGBDiaR.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(1, 1) + TwoDim(2, 0)))))
  47.     'End Sub
Just need a simple method to add Thanks
May 23 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.