Newbie: Assigning values to an array

J

Jack Doria

We store some objects in a dictionary, but need to pass those to a web
service that calls for an array of objects. I am getting an error "Object
reference not set to an instance of an object" after opening a page that
runs the following code. Any guidance would be appreciated.

Private Function orderLinesToArray(ByVal lines As CalculateOrderLines) As
Array

Dim ol As CalculateOrderLine

Dim arrNewLines(lines.Count - 1) As CalculateOrderRequestLine

Dim i As Integer = 0

For Each ol In lines.Values

arrNewLines(i).deliveryMethodCode = ol.deliveryMethodCode

arrNewLines(i).ItemSKUCode = ol.ItemSKUCode

arrNewLines(i).lineSequence = ol.lineSequence

arrNewLines(i).qty = ol.qty

arrNewLines(i).shipToPartyId = ol.shipToPartyId

i += 1

Next

Return arrNewLines

End Function
 
G

Guest

You need to create an instance for each array element:

For Each ol In lines.Values
'Create new CalculateOrderRequestLine object
arrNewLines(i) = New CalculateOrderRequestLine("constructor parms here")

arrNewLines(i).deliveryMethodCode = ol.deliveryMethodCode
arrNewLines(i).ItemSKUCode = ol.ItemSKUCode
........
 
J

Jack Doria

Thanks Dennis...I thought it had something do do with the absence of a
"New," but I just couldn't figure out where.

Jack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top