Reputation: 25080
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
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
Upvotes: 1
Views: 207
Reputation: 43743
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()
Upvotes: 2