Results 1 to 3 of 3

Thread: File Listbox auto select

  1. #1

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158

    Question

    I've got a filelistbox, and I want it to have a certain file selected when the form loads. I know it's probably a newbie question, but how can i do that? =)
    I've tried several things, and havent been able to do it. I keep getting runtime errors, whenever I try something.

    Any help would be appreciated.
    Thanks,

    Stephen

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Try something like:
    Code:
    Private Sub Form_Load()
        Dim lIndex As Long
        
        For lIndex = 1 To File1.ListCount
            If File1.List(lIndex) = "SomeFile.txt" Then
                File1.ListIndex = lIndex
                Exit For
            End If
        Next
    End Sub

  3. #3
    Guest
    You could also use:

    Code:
    File1.ListIndex = 0
    Or you can randomize it:

    Code:
    Function randomnumber(finished)
    Randomize
    randomnumber = Int((Val(finished) * Rnd) + 1)
    End Function
    
    Private Sub Command1_Click()
    i = randomnumber(File1.ListCount)
    File1.ListIndex = i
    End Sub

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