how to display images with delay

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.
Who is Participating?
CycLonEConnect With a Mentor Commented:
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...

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
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
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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
leeh0003Author Commented:
What does your variable Timer means?  Is it sometihing that we initialised or it's n internal function? Please advise.
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
All Courses

From novice to tech pro — start learning today.