|
-
Mar 29th, 2022, 12:26 AM
#1
Thread Starter
PowerPoster
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!
-
Mar 29th, 2022, 07:20 AM
#2
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
-
Mar 29th, 2022, 07:30 AM
#3
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
-
Mar 29th, 2022, 10:34 AM
#4
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).
-
Mar 29th, 2022, 10:57 AM
#5
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.
-
Mar 29th, 2022, 11:23 AM
#6
Re: How can I loop through listboxes to write the same list index to the same textlin
 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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|