Results 1 to 6 of 6

Thread: list(of string) question??? and loop question???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Question 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:
    1. do
    2. 'whatever i need to do
    3. iLengthofList = list1.count - 1
    4. 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
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Addicted Member BobTheBuilder.'s Avatar
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    149

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Addicted Member BobTheBuilder.'s Avatar
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    149

    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.

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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:
    1. Dim MyList As New Generic.List(Of String)
    2.         MyList.Add("test") 'adds value to list
    3.         'checks to see if list contains a certain value, if so, change the index of that value to something else
    4.         If MyList.Contains("test") Then
    5.             MyList(MyList.IndexOf("test")) = "new value"
    6.         End If
    7.  
    8.         'example of looping through the entire list
    9.         For Each str As String In MyList
    10.             MessageBox.Show(str) 'should display "new value" instead of the original "test"
    11.         Next
    Just an example of usage, you would, of course, replace the hard coded strings with the variables you are wanting to check...

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width