Solved

how to display images with delay

Posted on 2003-11-25
6
327 Views
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.
thanks
0
Comment
Question by:leeh0003
6 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
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.


Form1:

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

Expert Comment

by:dbrckovi
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
    Picture1.Refresh
End Sub
--------------------------------------------------------------
0
 
LVL 11

Expert Comment

by:dbrckovi
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
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

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

Expert Comment

by:dbrckovi
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
    Else
        Form1.BackColor = vbButtonFace
    End If
End Sub
----------------------------------------------
0
 
LVL 1

Accepted Solution

by:
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...

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now