What VB code will do this kind of rotation of files?

Posted on 2004-11-26
Last Modified: 2010-05-02
Folder "songs" contains 50 mp3 files.
It also contains a text file of all of the songs in the "songs" folder.

Folder "ready" contains nothing at the moment.

When I press a button:
I need VB code that will look at the text file in "songs" and take the first 4 songs in the list, and copy the associated files to folder "ready".
Next time I press the "button", the NEXT 4 songs from the text file in "songs" is put into folder "ready" and REPLACE the ones that were there.
This continues until all of the songs are used from folder "songs", then it starts again from the top.
If the code rotates the text file to reflect the used files moving to the bottom that's ok.
Can someone show me the code that will do this?
Question by:rbend

    Accepted Solution

    Try this -
    Private Sub Copy_Songs()
    On Error GoTo ErrHand

    Dim sSongsDir As String
    Dim sTextFile As String
    Dim sReadyDir As String
    Dim FString As String
    Dim lCtr As Long
    Dim iFileCopied As Integer
    Dim blnFound As Boolean
    blnFound = False
    lCtr = 1
    iFileCopied = 0
    sSongsDir = "C:\Songs"
    sTextFile = sSongsDir & "\Text.txt" 'Songs Text File
    sReadyDir = sSongsDir & "\Ready" 'Ready Dir

    Open sTextFile For Input As #1 'Open Text File
        Do While Not EOF(1)   ' Loop until end of file.
            Input #1, FString ' Read data
            If blnFound = False And CLng(GetSetting("MP3Songs", "List", "Current", 1)) = lCtr Then 'Get Next file from registry
                FileSystem.Kill (sReadyDir & "\*.*") 'Delete previous songs from "Ready"
                blnFound = True
            End If
            If blnFound Then
                If iFileCopied < 4 Then 'Copy 4 songs
                    FileSystem.FileCopy sSongsDir & "\" & Trim(FString), sReadyDir & "\" & Trim(FString) 'Copy Songs
                    iFileCopied = iFileCopied + 1
                    SaveSetting "MP3Songs", "List", "Current", lCtr 'Save Next File in Registry
                    Exit Do
                End If
            End If
            lCtr = lCtr + 1
        If EOF(1) = True Then 'Copied every files from Text File
            MsgBox "All Songs in Text File Copied"
            SaveSetting "MP3Songs", "List", "Current", 1 'Save Next File as 1st File
            MsgBox "Copied 4 Songs"
        End If
    Close #1

    Exit Sub


    Author Comment

    good thanks

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now