datagridview calculation-VBForums
Results 1 to 4 of 4

Thread: datagridview calculation

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2017
    Posts
    19

    datagridview calculation

    I'm triying to calculate the datagridview in the attachment by this code:

    Code:
    Dim PAEasayuk1 As Double  
            Dim PAEasayuk2 As Double
            Dim PAEasayuk As Double
           
    
            For PAEasa1 As Integer = 0 To DataGridView1.RowCount - 1
                For PAEasa2 As Integer = 1 To DataGridView1.RowCount - 1
                    For PAEasa3 As Integer = 1 To DataGridView1.RowCount - 1
    
                        PAEasayuk1 = DataGridView1.Rows(PAEasa1).Cells(0).Value
                        PAEasayuk2 = DataGridView1.Rows(PAEasa2).Cells(1).Value
    
                        If PAEasayuk2 > PAEasayuk1 Then PAEasayuk = 1 Else PAEasayuk = -1
    
                        DataGridView1.Rows(PAEasa3).Cells(1).Value = PAEasayuk
    
                    Next
                Next
    
            Next


    End of calculation all results are 1 or -1 . But, I want if it is big 1, otherwise -1
    Thanks for the answers.
    Attached Images Attached Images  

  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,126

    Re: datagridview calculation

    If I understand what you are trying to do correctly, I think you only need the one loop. See if you understand the following. If not, post back with more information.
    Code:
    Dim PAEasayuk1 As Double
    Dim PAEasayuk2 As Double
    Dim PAEasayuk As Double
    
    
    For PAEasa1 As Integer = 0 To DataGridView1.RowCount - 2
        Dim PAEasa2 As Integer = PAEasa1 + 1
    
        PAEasayuk1 = DataGridView1.Rows(PAEasa1).Cells(0).Value
        PAEasayuk2 = DataGridView1.Rows(PAEasa2).Cells(1).Value
    
        If PAEasayuk2 > PAEasayuk1 Then PAEasayuk = 1 Else PAEasayuk = -1
    
        DataGridView1.Rows(PAEasa2).Cells(2).Value = PAEasayuk
    
    Next

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2017
    Posts
    19

    Re: datagridview calculation

    Worked very well. Thank you very much.

    Last week, I asked "datagridview average calculation" question and didn't get a suitable answer.
    If it is not waste of time for you, can you look this thread and examine?

    Thank you so much.

  4. #4
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: datagridview calculation

    Curiousman

    If I'm not mistaken, you are referring to

    http://www.vbforums.com/showthread.p...ge-calculation

    If so, did you notice my post #7?

    Spoo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.