Results 1 to 4 of 4

Thread: Transferring listbox items to a textfile for saving.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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.

    Thanks!!

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Transferring listbox items to a textfile for saving.

    I expanded a bit on my other small ADO-Beginners-Demo, which is mentioned and downloadable here:
    http://www.vbforums.com/showthread.p...=1#post4645685

    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.

    Here's the Download:
    http://vbRichClient.com/Downloads/AdoStudents.zip

    And a ScreenShot:


    Hope this is useful for other DB-Novices too.

    Olaf

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Transferring listbox items to a textfile for saving.

    Hey Justin, I made this example for you.
    It will load or save choices, if student choices exists (in file) it will replace them.

    You could use an array for choices, but I hard coded 3 choices only, like the example you gave us.
    Attached Files Attached Files

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