Problem in Integer array in VB.net
-
My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance
-
My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance
-
My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance
kokilaB wrote:
Dim StepNumber() As Integer = Nothing
You declared an unbound array of Integers, then set it to Nothing. Bad idea. You also cannot assign values to an unbound array. The array has to have bounds in order to use it.
ds = bl.GetStepDS(Session.Item("TestCase").ToString())
If ds.Tables.Count > 0 Then
If ds.Tables(0).Rows > 0 Then
Dim StepNumber(ds.Tables(0).Rows.Count - 1) As Integer
For Aindex As Integer = 0 to ds.Tables(0).Rows.Count - 1
StepNumber(Aindex) = Aindex
StepNameList(Aindex) = record.Item(0).ToString()
Next
'
' Do whatever you need to save and/or return the array here, because
' it won't exist outside this nested If statement.
'
End If
End IfA guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007