Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Pdf (VB6)

    Not sure if this can be done but I'll ask anyway.

    We use an application to show various pdf documents.
    The docs use VB's pdf control to load the pdf document.
    When the form loads, a default document is always shown:

    <pre> Me.AcrobatPath = "L:MMPDFUtilitiesPDFViewer.pdf"
    Me.Pdf1.LoadFile Me.AcrobatPath</pre>


    Is it possible using a timer control and a users inactivity to randomly show a document from the same or a specified folder.
    The reason for this is I am creating a series of publications ie pdf docs giving repair information, it would be ideal to use them kind of like a screen saver.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Random Pdf (VB6)

    Put this function in a module:
    <code>
    Function SelectRandomFile( _
    ByVal strFolder As String, _
    ByVal strExt As String) As String
    Dim strFile As String
    Dim intCount As Integer
    Dim arr() As String
    Dim i As Integer

    On Error GoTo ErrHandler

    ' Trailing backslash is obligatory
    If Not Right(strFolder, 1) = "" Then
    strFolder = strFolder & ""
    End If
    strFile = Dir(strFolder & "*." & strExt)
    Do While Not strFile = ""
    intCount = intCount + 1
    ReDim Preserve arr(1 To intCount)
    arr(intCount) = strFile
    strFile = Dir
    Loop

    If intCount = 0 Then
    Exit Function
    End If

    Randomize
    i = Int(1 + Rnd * intCount)
    strFile = arr(i)
    SelectRandomFile = strFolder & strFile

    ExitHandler:
    Erase arr
    Exit Function

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Function
    </code>
    Use like this:
    <code>
    Me.AcrobatPath = SelectRandomFile("L:MMPDFUtilities", "pdf")
    Me.Pdf1.LoadFile Me.AcrobatPath</code>

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random Pdf (VB6)

    Hans
    Thank you once again.

    This code coupled with a project I found which monitors keyboard and mouse inactivity, works perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •