Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

opening files

ipfreelyipfreely Member Posts: 2
how could i get a list of all files in a directory and then choose a random one and display it?

-thanks in advance

Comments

  • phph Member Posts: 393
    : how could i get a list of all files in a directory and then choose a random one and display it?
    :
    : -thanks in advance
    :

    I gave it a shot for ya. slapped together some code. here ya go.

    add a dirbox drivebox commandbutton filebox and image control, insert this code and run it. I think i commented all the code, so this should be what you need :) very straight forward :)
    [code]
    'I simply assumed you wanted to 'Display' images. hope this code helps you :)


    Private Sub Command1_Click()
    Dim FileNumber As Long 'you could also use integer, long and integer are pretty
    'much the same.
    FileNumber = Rnd * File1.ListCount 'this tells vb to randomly choose one of the
    'files. In the future you will find the rnd
    'function to be very useful.
    File1.Selected(FileNumber) = True 'this tells vb to 'Select' this randomly chosen
    'file in the filelistbox.

    Image1.Picture = LoadPicture(File1.Path & "" & File1.FileName) 'this tells vb to
    'display the new
    'random file in the
    'imagebox, image1.

    End Sub

    Private Sub Dir1_Change()
    File1.Path = Dir1.Path 'this tells filelistbox to display the current path of the
    'dirlistbox.
    End Sub

    Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive 'this tells the dirlistbox to display the selected drive in
    File1.Path = Dir1.Path 'drive1 and tells filelistbox to follow suit.
    End Sub

    Private Sub Form_Load()
    File1.Pattern = "*.jpg;*.jpeg;*.gif;*.bmp" 'this tells filelistbox to only display
    'these file types.
    End Sub
    [/code]
    [red]ph[/red][blue][/blue][red]t[/red]
    [red]http://fade.to/phet[/red]
    [blue]12d.hypermart.net[/blue]
    [red][email protected][/red]

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    __ ( http://forcoder.org ) free video tutorials and ebooks about | C++ Go Ruby Visual Basic .NET MATLAB Python Visual Basic PHP C Scratch Swift R Perl Delphi Assembly Java JavaScript Objective-C C# PL/SQL Dart SAS ABAP Erlang LabVIEW Logo Apex ML Lua Ada Alice F# Awk Crystal Lisp D Prolog Julia Fortran Hack Bash Rust Kotlin Clojure FoxPro Scala Scheme COBOL Transact-SQL VBScript | _____

Sign In or Register to comment.