Home All Groups Group Topic Archive Search About

Newbie: Assigning values to an array

Author
9 Dec 2006 12:21 AM
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

Author
9 Dec 2006 12:38 AM
Dennis
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
........

--
Dennis in Houston


Show quoteHide quote
"Jack Doria" wrote:

> 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
>
>
>
>
>
Author
11 Dec 2006 6:58 PM
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

Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:89BE159E-C245-413B-AA69-E5366D245EF8@microsoft.com...
> 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
> .......
>
> --
> Dennis in Houston
>
>
> "Jack Doria" wrote:
>
>> 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
>>
>>
>>
>>
>>