Click here to Skip to main content
15,799,257 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The Random generator works fine. What I have a problem with is adding the rows and columns.
     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  diagonaly

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 below but results were faulty (worked but wrong answers)
 (Example Below)
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
    LblGBRowR1r0.Text = Convert.ToString(CInt(((TwoDim(0, 2) + TwoDim(0, 1) + TwoDim(0, 0)))))
    LblGBColC1c0.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 0) + TwoDim(2, 0)))))
    LblGBDiaL.Text = Convert.ToString(CInt(((TwoDim(0, 0) + TwoDim(1, 1) + TwoDim(2, 2)))))
    'End Sub

Just need a simple method to add Thanks
Updated 23-May-12 8:48am

Very bad. Work with data, not strings representing data. You can use 2D arrays, but changing the size of arrays would be a problem. If you need to change the size up to some maximum known in advance, use the array of maximum size from the very beginning. If it does not meet your requirements, use the generic type System.Collections.Generic.List. The list of lists of number will represent a 2D array (matrix) of numbers with variable size. Encapsulate this data type in some wrapper class which would allow only valid operations (supporting all nested array sized equal, etc.).

Share this answer
geparl 23-May-12 13:18pm    
Sorry you lost me or I you but all I want is to add each row or col. I am not antisipating making the array larger. If you know of a way I would appriciate being pointed in the right direction. I am not a programmer so i just wantr to keep this simple. But Thanks anyway.
Sergey Alexandrovich Kryukov 28-May-12 17:38pm    
I already pointed out two more reasonable alternatives: fixed size array or System.Collections.Generic.List. Which one is not clear?
Your first problem is the biggest. You're storing your data as text in a bunch of label controls. Don't! Controls are for displaying things, not for storing your working data.

You can start by storing your values in a 2 dimensional array. To assign your random values you can iterate through those elements using a couple of simple loops:
Dim RNG As New Random()
Dim values(3, 3) As Integer

For i As Integer = 0 to 2
    For j As Integer = 0 To 2
        values(i, j) = RNG.Next(RandomNumberLimit)

To add up a row of values is pretty easy:
Dim rowTotal As Integer
For i As Integer = 0 to 2
    rowTotal = rowTotal + values(i, 0)

If you really want to learn the basics, forget about the label controls for now and just output to either Debug or write a Console app instead.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900