1

i.e. if I am creating an array as such

        Dim webLinesArray() As OrderService.webdirect_WebLinesRow

How Can I add items to this array i.e. I want add an item as such

Dim webLine As New OrderService.webdirect_WebLinesRow
                webLine.OrderQty = quantity
                webLine.ProductCode = productId
                webLine.LineNumber = 1
                webLinesArray.add or something (webLine)

Just that last line I cant figure out how I can add items to the array

3 Answers 3

1

1) You cannot add an item into an array (they are of a fixed length) 2) You can, however, assign a value to a position in an array (webLinesArray() = foo)

You prob. want to use a List I'd guess, it will allow you to add items dynamically and behaves much like an array does (from the user/programmer standpoint)

Sign up to request clarification or add additional context in comments.

1 Comment

I agree, I almost never use arrays anymore, I always use List(of T)
1

You have to redim the array:

ReDim Preserve webLinesArray(webLinesArray.Length+1)
Now you can store the element at the last position. 

The Preserve keyword is for preserving the existing values in the array

Comments

0

For a basic array, you have to resize it and then assing the item to an index in the array, I don't think there is an add for a basic array.

Array.Resize(webLinesArray, Newsize)
webLinesArray(index) = Item

4 Comments

Yeah the only problem i see is that it needs to be dynamic size as I wont know the size beforehand
@StevieB if that's the case, what prevents you from using a List(of T)? That is dynamic and has an "Add" method.
From the API it looks to me like in the function I am passing this its an array its looking for as an parameter . I.e. <System.Xml.Serialization.XmlArrayAttribute(IsNullable:=true), System.Xml.Serialization.XmlArrayItemAttribute("WebLinesRow", IsNullable:=false)> ByVal WebLines() As webdirect_WebLinesRow
@StevieB You can still use List(of T) and call the ToArray() method on the List if that's what the API wants. The ToArray() method will convert the List(of T) to native Array of T.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.