Transferring listbox items to a textfile for saving.
Hi there folks. I am working on a prog to record what literacy stations students go to during their language arts period. I have a form that gives them choices where they want to go, and they click on the one they want to do. The back end basically just records their choices. Each student has a listbox called Studentchoices. They are in an array of 31, from 0 to 30. I can save the listboxes to text, but what I would like to do is this.
Lets say the students have 3 items in their listbox. Is there a way for when I press a command button to save the items for each student on the same line, perhaps divided by a comma. So it might save it as Choice1, Choice2, Choice 3, etc.
Then the next line of the textfile would have the next student's picks, and it would loop until all 31 students have been recorded in a file called StudentPicks.txt?
I have saved 1 listbox to a textfile before, but not 31 of them. I think it would be handy though, and the students really like going up to pick their choices.
Re: Transferring listbox items to a textfile for saving.
Not sure I understand but maybe this will give you some ideas.
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim indx As Integer
Dim strSelected() As String
' Selected
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
ReDim Preserve strSelected(indx)
strSelected(indx) = List1.List(i)
indx = indx + 1
End If
Next i
Debug.Print "Selected items - " & Join(strSelected, ",")
' All
ReDim strSelected(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
strSelected(i) = List1.List(i)
Next i
Debug.Print "All items - " & Join(strSelected, ",")
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 10
List1.AddItem i
Next i
End Sub
Also the above Demo created everything from scratch (the DB-File, as well as the Table) - and made use
of Recordset-Events to ensure proper Navigation and Binding-Behaviour.
The new one does all that too - but goes only a little bit further, introducing small UserControls, to handle the
Navigation and the Vertical-Field-Editing - and also shows already the beginnings of a bit of "DB-normalization",
since it now creates 3 Tables dynamically instead of a single one:
- Students (with ID, FirstName, LastName, BirthDay ... to define only the Students-Attributes)
- Choices (with ID, Name, Description ... for the Choice-Definitions)
- StudentsChoices (a table which combines StudentIDs and ChoiceIDs in two Columns)
Sounds more scary than it is - because everything is structured and the code-volume in every module is
comparably small (for what the Demo does, keeping everything "in sync" - even the small Extra-Form for the Choices).
The most code is in fStudents (50 lines or so) - all the rest is only about 20-30 lines per module.