And again, out of range



  • Let's go to the initialization of DataGridView. ♪ ♪

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    Dim arr() As Integer
    Dim j, i, length As Integer
    Dim number As Integer
    Dim nullCount, positiveCount, negativeCount As Integer
    
    While length <= 0
        length = InputBox("Введите длину массива (неотрицательное ненулевое число):")
    End While
    
    ReDim arr(0 To length)
    
    For j = 0 To length - 1
        number = InputBox("Введите целое число (отрицательное или положительное).")
        If IsNumeric(number) Then
            arr(j) = number
        Else
            j -= 1
            MsgBox("Вводите число!")
        End If
    Next j
    
    DataGridView1.ColumnCount = length
    DataGridView1.RowCount = 1
    negativeCount = 0
    nullCount = 0
    positiveCount = 0
    
    
    For i = 0 To length - 1
        DataGridView1.Item(1, i).Value = arr(i)
        If arr(i) > 0 Then
            positiveCount += 1
        ElseIf arr(i) Like 0 Then
            nullCount += 1
        Else
            negativeCount += 1
        End If
    Next i
    
    Label1.Text = "Количество отрицательных элементов: " + negativeCount.ToString()
    Label2.Text = "Количество нулевых элементов: " + nullCount.ToString()
    Label3.Text = "Количество положительных элементов: " + positiveCount.ToString()
    
    Me.Opacity = 100
    

    End Sub



  • DataGridView1.Item(i, 0).value = arr(i)You have RowCount=1, followed by. 0and change the indices to the locations, it must be. Reference https://msdn.microsoft.com/ru-ru/library/ms158656(v=vs.110).aspx

    Public Property Item (
      columnIndex As Integer,
      rowIndex As Integer
    ) As DataGridViewCell
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2