How to go from row 1 to 1000 without writing every row or column 1000 times?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Big P
    New Member
    • Jan 2011
    • 11

    How to go from row 1 to 1000 without writing every row or column 1000 times?

    I need a faster way of going from row 1 to 1000 without writing every row or colunm 1000 times.

    Do I need to declare it?
    Dim .... as integer ?
    I need to save memory. Please help

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If TextBox1.Text = 5 Then
                '*NOTE:*Cell  Cell 0 + Cell 1 + Cell 2 and so on til  Cell 20
    
                DataGridView1(0, 0).Value = 1
                DataGridView1(0, 1).Value = 1
                DataGridView1(0, 2).Value = 1
    
                '*NOTE:*Row 1+2+3 and so on till 1000
                DataGridView1(1, 0).Value = 1
                DataGridView1(2, 1).Value = 1
                DataGridView1(3, 2).Value = 1
    
                '*NOTE:*Sum Rows 0, Cell 0 + Cell 1 + Cell 2 and so on til  Cell 20
                TextBox2.Text = DataGridView1(0, 0).Value + DataGridView1(0, 1).Value + DataGridView1(0, 2).Value  'and so on till 20
    
                '*NOTE:*Sum Row 0 + Row 1 + Row 2 and so on till 1000
                TextBox3.Text = DataGridView1(0, 0).Value + DataGridView1(1, 0).Value + DataGridView1(2, 0).Value 'and so on till Row 1000
    
            End If
    
        End Sub
    Last edited by Niheel; Jan 25 '11, 02:04 PM. Reason: code tags, and always ask question and description first then show code.
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Something quick and dirty, like this?
    Code:
    dim i as long
    dim s
    for i = 1 to 1000
      ''walk down the column
      s = s + DataGridView(0, i).Value
      DataGridView1(0, i).Value = 1
      ''walk across the row
      s = s + DataGridView(i, 0).Value
      DataGridView1(i, 0).Value = 1
    next i
    Cheers!
    Oralloy

    Comment

    • Big P
      New Member
      • Jan 2011
      • 11

      #3
      Thanks a lot, really helped me to have an idea!
      I got it this way now:
      Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              
              Me.TextBox1.Text = 1
              Me.TextBox2.Text = 1
          End Sub
      
         
      
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim i As Integer
              Dim s As Integer
              For i = 1 To 6
                  ''walk across the row 
      
                  s = s + DataGridView1(i, 0).Value
      
              Next i
      
      
              If TextBox1.Text = 1 And TextBox2.Text = 1 Then
                  DataGridView1(7, 0).Value = s
              End If
          End Sub
      Last edited by Niheel; Jan 25 '11, 02:03 PM. Reason: use code tags and proper spelling + Grammar.

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        Big P,

        Good on you, Bro!

        Keep it up and you'll be an expert in no time.

        If you have more questions, don't hesitate to ask. Sometimes, even the effort of asking seems to lead us to a solution. If not, there's lots of bright folks on the site who love to help.

        Cheers!
        Oralloy

        Comment

        Working...