Solved

OnTimer event coding

Posted on 2003-11-18
17
731 Views
Last Modified: 2009-07-29
I would like to have images appear and disappear one after the other on the Time Interval set on my form.  This is my code so far, but I can not get the OnTimer code to compile correctly:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
   Me.Image0.Visible = True
   Me.Image0.Visible = False
   Me.OnTimer.Image1.Visible = True
 
   
End Sub

Any help please?
0
Comment
Question by:cpopham
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9772802
Hey cpopham!

 Code for that type operation needs to be in the OnTimer event of the form.

  Private Sub Form_Timer
    ...
    your code here
    ...
  End Sub

This line:
  Me.OnTimer.Image1.Visible = True
is what the compiler doesn't like.

Explain further what exactly you want these image controls to do?

 


regards
Jack
0
 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9772858
Hi,

On Form Property (Click on Left Top Box of the Form to Select Form and then Click on Property Icon or View/Properties), key Time Interval in Milliseconds.  Then on Timer Event of form type following code:

Private Sub Form_Timer()
if me.Image.Visible = True then
me.Image.Visible=False
else
me.image.visible=true
end if
End Sub
0
 

Author Comment

by:cpopham
ID: 9772873
Jack,
I am just wanting a series of images to appear one after the other.  So if I coded like this:

Private Sub Form_Timer
   Me.Image0.Visible = True
   Me.Image0.Visible = False
   Me.Image1.Visible = True
 
End Sub

Would it work on the time interval?  Or do I need to add to something to the code so that it will process certain parts of the code at the desired interval?
0
 

Author Comment

by:cpopham
ID: 9772912
The series is about 8 images long also...  So I would want it to loop back to the first image after until they clicked to go somewhere else...
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9772965
Private Sub Form_Timer

  static ImgNum as Byte
   imgnum = imgnum + 1
   if imgnum>8 then imgnum = 0

   Me.Image0.Visible = (ImgNum = 0)
   Me.Image1.Visible = (ImgNum = 1)
   Me.Image2.Visible = (ImgNum = 2)
   Me.Image3.Visible = (ImgNum = 3)
   Me.Image4.Visible = (ImgNum = 4)
   Me.Image5.Visible = (ImgNum = 5)
   Me.Image6.Visible = (ImgNum = 6)
   Me.Image7.Visible = (ImgNum = 7)
   Me.Image8.Visible = (ImgNum = 8)
 
End Sub

Add error trapping and it's something like that...

0
 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9773047
Hi again,

If you want to display 8 images in series, name all images in series like Image1, Image2...... Image8.

Make all Images Invisible in Design.  Visible=No

Dim ImageNumber as Integer

ImageNumber=1

Private Sub Form_Timer

Select Case ImageNumber
    case 1
          me.Image1.visible=True
    case 2
          me.image2.visible=ture

so on upto 8

If Imagenumber <=8 then
    ImageNumber=ImageNumber+1
else
ImageNumber=1
end if
End sub
 
0
 

Author Comment

by:cpopham
ID: 9773147
Nothing is visible when I put that code in Jack.  This is what I have so far:
0
 

Author Comment

by:cpopham
ID: 9773206
JagDish,

I tried it the way you mentioned and nothing is visible.  I also coded it this way and none of the images are visible:

Private Sub Form_Timer()

Dim ImageNumber As Integer

ImageNumber = 1

Private Sub Form_Timer()

Select Case ImageNumber
    Case 1
          Me.Image0.Visible = True
          Me.Image7.Visible = False
    Case 2
          Me.Image1.Visible = True
          Me.Image0.Visible = False
    Case 3
          Me.Image2.Visible = True
          Me.Image1.Visible = False
    Case 4
          Me.Image3.Visible = True
          Me.Image2.Visible = False
    Case 5
          Me.Image4.Visible = True
          Me.Image3.Visible = False
    Case 6
          Me.Image5.Visible = True
          Me.Image4.Visible = False
    Case 7
          Me.Image6.Visible = True
          Me.Image5.Visible = False
    Case 8
          Me.Image7.Visible = True
          Me.Image6.Visible = False
         
If ImageNumber <= 8 Then
    ImageNumber = ImageNumber + 1
Else
ImageNumber = 1
End If
End Sub
 

0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9773247
Hi,

have you changed the Time Interval Property of Form.  You Must put TimeInterval in Milliseconds.  Don't Try very small number.  Try say at least 10000

0
 

Author Comment

by:cpopham
ID: 9773370
I wanted it to flash kind of fast.  I set it to .5 which should be .5 sec I will extend the time interval and try it.. Nope still nothing.
0
 

Author Comment

by:cpopham
ID: 9773396
JagDish,
I am also getting a compile error on the End Sub:

Select Case without end select..
0
 

Expert Comment

by:stawicki
ID: 9774335
no, half a second is 500!  The time is in milliseconds  - thats 1000 per second!
0
 

Author Comment

by:cpopham
ID: 9775869
I know it is in milliseconds.  I was saying I just wanted them very brief like half a second.  Anyone have any ideas?
0
 
LVL 1

Expert Comment

by:ErnestMcDuff
ID: 9778342
One of those days you find a nice question to bite your teeth into....

Dear cpopham,

I got it working and this is how I did it:

1) Put into a empty module (the image array has to be initialize public (see ps)) the next lines:

Option Compare Database
Option Explicit
Public arImage(1 To 8) As String
Public nrImage As Integer


2) Put into the Form_Open() prcodeure the next lines

    nrImage = 1
    arImage(1) = "C:\windows\Blue Lace 16.bmp"
    arImage(2) = "C:\windows\Coffee Bean.bmp"
    arImage(3) = "C:\windows\Feathertexture.bmp"
    arImage(4) = "C:\windows\Gone Fishing.bmp"
    arImage(5) = "C:\windows\Greenstone.bmp"
    arImage(6) = "C:\windows\Prairie Wind.bmp"
    arImage(7) = "C:\windows\Rhododendron.bmp"
    arImage(8) = "C:\windows\River Sumida.bmp"

3) Furthermore, put into your form_timer routine the following:

    Me.Image0.Picture = arImage(nrImage)
    nrImage = IIf(nrImage > 7, 1, nrImage + 1)

Please remove any other image you have available now. My little routine just replaces the source for the picture.
As you can see I've used some standard pics which, ofcourse you can change to whatever you want.

Hope you like it..
Ernest McDuff

PS If someone can tell how I can declare a variable public in the form's themselves, please let me know.
Not bad for an Access-newbee....
0
 
LVL 1

Accepted Solution

by:
Jagdish_Bodani earned 125 total points
ID: 9779554
Hi,

Given below is complete code.  I have tested it and it works perfect.

Create as many images as you want on form.  Make them invisbile in design mode.
Make sure that you key desired time interval.

Code is under:

Option Compare Database
Option Explicit

'variable declared in general section outside procedure

Dim imagenumber As Integer



Private Sub Form_Load()
imagenumber = 1
End Sub


Private Sub Form_Timer()


Select Case imagenumber
    Case 1
          Me.Image1.Visible = True
          Me.Image3.Visible = False
    Case 2
          Me.Image2.Visible = True
          Me.Image1.Visible = False
    Case 3
          Me.Image3.Visible = True
          Me.Image2.Visible = False
End Select

If imagenumber <= 3 Then
    imagenumber = imagenumber + 1
Else
imagenumber = 1
End If

End Sub
0
 

Author Comment

by:cpopham
ID: 9782706
I will try that upon my return to work or perhaps tonight.  We got hit with the heavy rains.
0
 

Author Comment

by:cpopham
ID: 9787397
That works great and does exactly what I need it to do.  Thanks for the help!!!
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

Suggested Solutions

Title # Comments Views Activity
HasData 9 37
Send a .ZPL file to a network printer from Access 8 53
T-SQL for SS2000 -- get position of char(13) in a long text field 11 31
MS Access Tables Linking 6 42
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

895 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

11 Experts available now in Live!

Get 1:1 Help Now