1

i'm using vb.net i have the following object array that i'm trung to extract all the true value from give it a name and add it to an array here is the object array enter image description here

this is what i have tried so far :

  Dim myarray() As String
        Dim number As Integer = 0
        If resultArray(0).BolComment Then

            myarray(number) = "comment"
            number = number + 1
        End If
        If resultArray(0).BolComplete Then

            myarray(number) = "complete"
            number = number + 1
        End If
        If resultArray(0).BolFinished Then

            myarray(number) = "Finished"
            number = number + 1
        End If
        If resultArray(0).BolOutCome Then

            myarray(number) = "OutCome"
            number = number + 1
        End If
        If resultArray(0).BolStatred Then

            myarray(number) = "Started"
            number = number + 1
        End If
        If resultArray(0).BolUser Then

            myarray(number) = "User"
            number = number + 1
        End If

this is giving me an error : the variable has been used before

Question how can i extract all the items that have the true value and push it to a new array with giving it a new name Thanks

5
  • 3
    Any reason not to use a List(Of String)? It'll make your code significantly simpler... Commented Aug 23, 2012 at 19:50
  • to be honest i don't know how to do this... Thanks Commented Aug 23, 2012 at 19:59
  • What line is throwing the error? You know you have resultArray(x) and resultArray(0)? Commented Aug 23, 2012 at 19:59
  • @Blam i change it to illustrate Commented Aug 23, 2012 at 20:02
  • 1
    I see no change. Which line is throwing the error? Commented Aug 23, 2012 at 20:11

1 Answer 1

2

I think your problem is that you are not initializing the array to a specific size, nor are you re-sizing it each time you add a new item. However, it would be better to just use the List(T) class:

Dim list As New List(Of String)()
If resultArray(x).BolComment Then
    list.Add("comment")
End If
If resultArray(0).BolComplete Then
    list.Add("complete")
End If
If resultArray(0).BolFinished Then
    list.Add("Finished")
End If
If resultArray(0).BolOutCome Then
    list.Add("OutCome")
End If
If resultArray(0).BolStatred Then
    list.Add("Started")
End If
If resultArray(0).BolUser Then
    list.Add("User")
End If

Then, if you need it as an actual array, do this:

Dim myarray() As String = list.ToArray()
Sign up to request clarification or add additional context in comments.

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.