list(of string) question??? and loop question???
This is just a simple question.
I go through my list and use the value to search a database. Then when i get the results back i remove that value from the list. Now if i then add another item to the list then will it add it to the end or will it put it in the position of the value i removed?
Also i need to loop through that list so that every item is used. At the moment i am using
VB Code:
do
'whatever i need to do
iLengthofList = list1.count - 1
loop while iLengthofList <> 0
where iLengthofList is an integer. Now is there a more efficient way of doing this or is this it when takin into consideration that in the loop i will be changing the length of the list constantly?
Thanks for any advice on either of my questions.
B.T.W I am using .net compact framework 2.0 Windows Mobile 5.0
Thanks again
:afrog:
Re: list(of string) question??? and loop question???
Adding items via the .Add function (i presume) will add them to the end of the list, you can insert items into the middle if you wanted as well.
There is often a more efficient way of doing something than looping through a listing, but it is hard to really say without knowing what you are really doing.
Re: list(of string) question??? and loop question???
I have a questionnaire with several questions (some of them skip questions). What i need to do is go through the questionnaire when an answer needs to be changed and get all the questions that are going to be affected by the change and delete the results already saved. So i take the question that had its answer changed (each question has a reference number called questRef) and getting all the questions that have a property called skipQuestion equal to the questRef and then for each of those questions i get all the questions that have skipQuestions equal to their questRef (if that makes sense). So i was gonna go through the list and store all unique values in a separate array (or list). And then later on in the program i need to go through the array and delete all the results where the questRef equals the array element.
I hope this makes sense....if you need anything else explaining then jus let me know!
Re: list(of string) question??? and loop question???
If this is going into a database of some sort it might be easier to set up a dataset and binding that way it will take care of everything when something gets changed.
Check out the SQLdatasouce object.
Re: list(of string) question??? and loop question???
You can modify the list without creating a seperate list, using a combination of the .Contains method and .IndexOf.. a short sample is below:
VB Code:
Dim MyList As New Generic.List(Of String)
MyList.Add("test") 'adds value to list
'checks to see if list contains a certain value, if so, change the index of that value to something else
If MyList.Contains("test") Then
MyList(MyList.IndexOf("test")) = "new value"
End If
'example of looping through the entire list
For Each str As String In MyList
MessageBox.Show(str) 'should display "new value" instead of the original "test"
Next
Just an example of usage, you would, of course, replace the hard coded strings with the variables you are wanting to check...
Re: list(of string) question??? and loop question???
Thanks for all you're help....i'll have a go with you're suggestions and see what i can get.
I'll let you know how things go.
Thanks again
:thumb: