Results 1 to 6 of 6

Thread: How can I loop through listboxes to write the same list index to the same textline?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    How can I loop through listboxes to write the same list index to the same textline?

    Hi there folks! I am working on saving Math data my students are entering, into a textfile so I can view it later. I have 3 listboxes. StudentNameList, StudentAnswerList, StudentMarkList.

    Here I am creating a textfile to write into
    VB Code:
    1. 'Save the data to a textfile.
    2.  
    3. Dim iFileNo As Integer
    4. iFileNo = FreeFile
    5. 'open the file for writing
    6. Open App.Path & "\Data" & "Grade " & GradeLBL.Caption & " SavedData" & "-" & DateLBL.Caption & ".txt" For Output As #iFileNo
    7. 'please note, if this file already exists it will be overwritten!
    8.  
    9.  
    10.  
    11. 'close the file (if you dont do this, you wont be able to open it again!)
    12. Close #iFileNo

    After the file is made and open, I would like to loop through the lists, and for each list index ( like StudentNameList(0), StudentAnswerList(0), and StudentMarkList(0). I would like to save to the same line of the textfile. Then go to the next index of the lists, (1), and so on.

    Would anyone here know a trick for doing that?

    Thanks a lot!

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: How can I loop through listboxes to write the same list index to the same textlin

    Well if all three lists have the same number of entries then you just need one loop where you grab items from all three lists, then write that to your file
    Something like
    Code:
    For x=0 to list1.listcount-1
         OutString=List1(x) &"," & List2(x) & "," & list3(x)
         Print #iFileNo, OutString
    Next

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: How can I loop through listboxes to write the same list index to the same textlin

    Why even 3 ListBoxes? a single ListView or one of those FlexGrids with 3 Columns and you're done
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: How can I loop through listboxes to write the same list index to the same textlin

    Well if all three lists have the same number of entries
    Do they? Is there a relationship to Name, Answer and Mark? Seems strange, at least the nomenclature of your listboxes. Can you supply an image of the three listboxes once populated?

    And, probably, if there IS a direct relationship, AND the entries in each list are in the 'correct' order, then what Zvoni suggests MIGHT be a better option...(one can SEE those relationships much more clearer than having three listboxes).

    So, what do your listboxes look like?

    Sammi
    Sam I am (as well as Confused at times).

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: How can I loop through listboxes to write the same list index to the same textlin

    btw I just answered the question at face value but I agree with the other posts that 3 list boxes is a strange way to do this. A grid or listview would make much more sense.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: How can I loop through listboxes to write the same list index to the same textlin

    Quote Originally Posted by DataMiser View Post
    btw I just answered the question at face value but I agree with the other posts that 3 list boxes is a strange way to do this. A grid or listview would make much more sense.
    I know.
    Sam I am (as well as Confused at times).

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