Populate array list from Excel

pricejt

New member
Joined
May 8, 2007
Messages
3
Programming Experience
3-5
Can someone tell me what im doing wrong. In my function ConvertToStringArray im getting an error object reference not set to an instance of an object When it goes to add the value to theArray(i-1) in my else statement.

VB.NET:
Dim i as Integer 
For i = 1 To 2 step i + 1
     Dim range as excel.Range = objworksheet.Range("A" + i.ToString(), "B" + i.ToString())
Dim myvalues as system.array = CType(range.Cells.value, System.Array)
Dim strArray() as String = ConvertToStringArray(myValues)

ListView1.Items.Add(New ListViewItem(strArray))
Next

End Sub

Public Function ConvertToStringArray(ByVal values As System.Array) as String()

Dim theArray() as String
Dim i as integer 

Try

For i = 1 to Values.Length Step i + 1
If values.GetValue(1,i) = Nothing Then
   theArray(i-1) = ""
Else
   theArray(i-1) = CType(values.GetValue(1,i).ToString(), String)
End If
Next

Return theArray

Catch ex as exception 
   MsgBox(ex.Message)
End Try
End Function
 
Back
Top