|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie: Assigning values to an arrayservice 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 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 ........ -- Show quoteHide quoteDennis 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 > > > > > 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 >> >> >> >> >>
destroying/releasing objects from memory?
Threading Delegate Question vbs to vb.net Error: The transport failed to connect to the server This code demonstrates a problem using a treeview twice How to Insert field and value into another grid Looking for suggestions on how to do something how 2 approximate 0.1 to be 1 slow form backimage load @ vb.net Reading int64 from file & converting to DateTime |
|||||||||||||||||||||||