1

I have a little syntax declare problem in VB.Net.

Dim proxy As USImportoerServiceTypeClient = DMRUtils.CreateAndConfigureClient()

Dim request As New USDeclare_I()
request.DeclareCollection = New US_ITypeDeclare() {}
For Each KES In request.DeclareCollection
    KES.DeclareCollectionStructure.DeclareCollectionValidDate = DateTime.ParseExact(txtDeclareDate.Text, "dd-MM-yyyy", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
Next

This above code do not work, becase the "US_ITypeDeclare() {}" is empty an only contains a new DeclareCollectionStructure

How do I declare a KoeretoejErklaeringStructure to this an set this date value til "DeclareCollectionStructure.DeclareCollectionValidDate" ?

Best regards from Denmark

2
  • You are trying to For Each over the array, but the array is empty. Where are the objects suppose to be coming from? Commented Jun 7, 2012 at 14:10
  • 1
    Aside from very specific uses to their advantage, arrays are a rather clumsy and antiquated way of storing and managing information in .NET. Perhaps lists or collections would better suit this application. Commented Jun 7, 2012 at 14:20

1 Answer 1

2

Arrays have a fixed length, which is declared when the array is created. Therefore your array will always have a length of 0.

Use a List(Of T) instead. Lists grow dynamically when you add items to them.

request.DeclareCollection = New List(Of US_ITypeDeclare)
Dim newItem = new US_ITypeDeclare()
newItem.DeclareCollectionStructure.DeclareCollectionValidDate =  _
    DateTime.ParseExact(txtDeclareDate.Text, "dd-MM-yyyy", _
                System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
request.DeclareCollection.Add(newItem)
' Now the list contains one item

Of cause you will have to adapt the definition of DeclareCollection to be a list instead of an array.

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

3 Comments

Thank you very much, Oliver. I think we are close to a solution, but there is a litlle issue in the first line. request.DeclareCollection = New List(of US_ITypeDeclare) is not walid an in the error tooltip is says: "Cannot be converted to a 1-dimentional array of US_ITypeDeclare", maybe becase the US_ITypeDeclare is an multi-array of classes, as defined above.
PLEASE HELP ... If posible. :-)
As I said, you will have to change DeclareCollection to be a list. Public DeclareCollection As List(Of US_ITypeDeclare). Another option is to keep the array but initialize it with a constant length of one (it's hard to say from here) Dim newItem = new US_ITypeDeclare(1)

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.