1
What would be correct technique not to repeat the same code for these two overloads or maybe not to have the overloads?
It happens that sometimes I have to pass a parameter that is a string array and other times I pass integer array. If I don’t type the parameters, does not work, because the compiler complains that it cannot convert integer to object.
Private Sub CarregarArraysPeloDgv(ByRef dgv As DataGridView, ByRef a() As String)
' REDIMENSIONAR
If a Is Nothing Then
ReDim a(dgv.Rows.Count - 1)
Exit Sub
End If
If dgv.Rows.Count > a.Count Then
ReDim a(dgv.Rows.Count - 1)
End If
' ALIMENTAR
Dim x As Integer = 0
For Each row As DataGridViewRow In dgv.Rows
a(x) = Val(row.Cells(0).Value)
x = x + 1
Next
End Sub
Private Sub CarregarArraysPeloDgv(ByRef dgv As DataGridView, ByRef a() As Integer)
' REDIMENSIONAR
If a Is Nothing Then
ReDim a(dgv.Rows.Count - 1)
Exit Sub
End If
If dgv.Rows.Count > a.Count Then
ReDim a(dgv.Rows.Count - 1)
End If
' ALIMENTAR
Dim x As Integer = 0
For Each row As DataGridViewRow In dgv.Rows
a(x) = Val(row.Cells(0).Value)
x = x + 1
Next
End Sub
Every type derives from 'Object' in . Net, there is no way to caste the int for obj?
– Ronaldo Araújo Alves
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero