Link to home
Start Free TrialLog in
Avatar of cpopham
cpopham

asked on

OnTimer event coding

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?
Avatar of jadedata
jadedata
Flag of United States of America image

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
Avatar of Jagdish_Bodani
Jagdish_Bodani

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
Avatar of cpopham

ASKER

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?
Avatar of cpopham

ASKER

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

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
 
Avatar of cpopham

ASKER

Nothing is visible when I put that code in Jack.  This is what I have so far:
Avatar of cpopham

ASKER

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
 

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

Avatar of cpopham

ASKER

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.
Avatar of cpopham

ASKER

JagDish,
I am also getting a compile error on the End Sub:

Select Case without end select..
no, half a second is 500!  The time is in milliseconds  - thats 1000 per second!
Avatar of cpopham

ASKER

I know it is in milliseconds.  I was saying I just wanted them very brief like half a second.  Anyone have any ideas?
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....
ASKER CERTIFIED SOLUTION
Avatar of Jagdish_Bodani
Jagdish_Bodani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cpopham

ASKER

I will try that upon my return to work or perhaps tonight.  We got hit with the heavy rains.
Avatar of cpopham

ASKER

That works great and does exactly what I need it to do.  Thanks for the help!!!