Solved

how to display images with delay

Posted on 2003-11-25
6
329 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now