0

I have tried a number of different things but cant seem to find the right syntax to initialize this array of strings.

I have it in a custom class

Public Class datahere

    Public Property Name As String
    Public Property parameters() As String
    Public Property elem As XElement

End Class

and I declare it like so

Dim xdata(newdata.Count) As datahere

But not sure how to go about using it. I use the other variables like so

xdata(3).Name = "TEST"

2 Answers 2

1

Try like this ..

First change like this

Public Property parameters As List(Of String)

And create array class

Dim ListDH as List(Of DataHere)

Dim par as New Parameter
par.Add("Any value")

Dim DH as New DataHere

DH.Name = "Test"
DH.Parameter = par
DH.Property = ....

ListDH.Add(DH)

So you can access if by

ListDH(0).Name          '-----> to get Name of first array ("TEST")

ListDH(0).Parameter(0)  '-----> to get First array of Parameter from the list ("Any value")
Sign up to request clarification or add additional context in comments.

2 Comments

Hey, but what about the array of strings? That is the thing I am having trouble with and would run in to the same problem with the list
How is this the selected answer when it doesn't answer the question? The question asks how to declare an array of strings, and this answer says how to create a list(of string).
1

Although I would recommend using a List(of String) for your Parameters Property, if you insist on using arrays you can do the following.

First change the parameters property to the following:

Public Property parameters As String()

Keep in mind that xdata(3).parameters(0) will be nothing. To change that you would specify the number of items in the array like so:

ReDim xdata(3).parameters(0)
'Give it a value
xdata(3).parameters(0) = "Test 1"

If you want to add additional items you have to redefine the array. To prevent losing your existing data use the Preserve Keyword:

ReDim Preserve xdata(3).parameters(1)
'Give the second item in the array a value
xdata(3).parameters(1) = "Test 2"

To get your values is pretty straight forward:

Dim strSecondParameters As Strign = xdata(3).parameters(1)

Comments

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.