how to display images with delay

Posted on 2003-11-25
Last Modified: 2012-05-04
the current problem that i'm facing now is, i want to display one image after another with a delay in between but i'm only seeing the last image.
please help.
Question by:leeh0003
LVL 17

Expert Comment

ID: 9823039
Use the Pause() sub shown below to implement the delays you want. You can use the Sleep() API function also but it will cause the entire thread to "sleep" which you probably won't want to happen.


Option Explicit
Public Sub Pause(ByVal Interval As Integer)
    Dim Current As Integer
    Current = Timer
    Do While Timer - Current < Val(Interval)
End Sub
Private Sub Form_Load()
    MsgBox "Test 1"
    Call Pause(3) 'Pause 3 seconds
    MsgBox "Test 2"
End Sub
LVL 11

Expert Comment

ID: 9823055
Try using timer.
Dim image(4) As String                                  'Create a string array which will store paths
Dim counter As Integer                                  'Counter used by Timer

Private Sub Form_Load()
    image(0) = "c:\test\pic1.bmp"                       'Set paths to your images
    image(1) = "c:\test\pic2.bmp"
    image(2) = "c:\test\pic3.bmp"
    image(3) = "c:\test\pic4.bmp"
    counter = 0
    Timer1.Interval = 200                               'Set interval between two differrent images (miliseconds)
End Sub

Private Sub Timer1_Timer()
    counter = counter + 1
    If counter > UBound(image) Then counter = 0         'If counter exceeds the last picture index then set it back to 0
    Picture1.picture = loadimage(image(counter))        'Display the picture
End Sub
LVL 11

Expert Comment

ID: 9823064
If you don't want images to show in loop then use       >>    If counter > UBound(image) Then Timer1.Enabled = False      <<     instead of               If counter > UBound(image) Then counter = 0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Author Comment

ID: 9823069
What does your variable Timer means?  Is it sometihing that we initialised or it's n internal function? Please advise.
LVL 11

Expert Comment

ID: 9823177
Timer is a control in Visual Basic (Little stop watch icon in tool bar), which can be used to run one code several times using interval.

In order to see how it works. Create new standard exe project.
Drag Command button and timer control to a form.

Click on newly created Timer1 control and set its interval property to 500 (miliseconds)

Paste this code:    When you click on command button, background color should start blinking.
Private Sub Command1_Click()
    Timer1.Enabled = True                   'Start the timer
End Sub

Private Sub Form_Load()
    Timer1.Enabled = False                  'Ensure that timer is disabled after loading a form
End Sub

Private Sub Timer1_Timer()                      'This is the code that timer executes every time
    If Form1.BackColor = vbButtonFace Then              'routine for changing colors
        Form1.BackColor = vbHighlight
        Form1.BackColor = vbButtonFace
    End If
End Sub

Accepted Solution

CycLonE earned 125 total points
ID: 9824369
I have a very easy solution, try it ;-)

add an ImageList to your project, add the images to the imagelist...

then using a timer: specify the interval you want...
and cycle through the images by using a variable and incrementing the variable each time the timer is triggered... using this variable as the imagelist index select the pictures...


Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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