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:
'Save the data to a textfile.
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for writing
Open App.Path & "\Data" & "Grade " & GradeLBL.Caption & " SavedData" & "-" & DateLBL.Caption & ".txt" For Output As #iFileNo
'please note, if this file already exists it will be overwritten!
'close the file (if you dont do this, you wont be able to open it again!)
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!
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
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
Re: How can I loop through listboxes to write the same list index to the same textlin
Quote:
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
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.
Re: How can I loop through listboxes to write the same list index to the same textlin
Quote:
Originally Posted by
DataMiser
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.