?
Solved

using a doevent with a screen saver

Posted on 1998-12-03
3
Medium Priority
?
246 Views
Last Modified: 2010-05-03
I want to write a VB program that works as a screen saver/security program.
The first form will have one type of animation on it that fills the screen, then
with a key press event, the second form with a different animation program
will start. With a mouse click, form 3, a password screen, will come in.
How and where do I place the DoEvent to stop the animation loop. Do you
have any examples of this kind of a program?
Thank you
0
Comment
Question by:rscptn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
trillo earned 400 total points
ID: 1448075
First lets make a simple Draw routine (it will draw a circle with random dimentios.

Public Sub Draw(canvas as Object)
    Dim x As Integer
    Dim Y As Integer
    Dim radius As Integer
    Dim Colr As Long
    Dim i As Integer
    ScreenWidth = canvas.Width
    ScreenHeight = canvas.Height
    x = Rnd * ScreenWidth
    Y = Rnd * ScreenHeight
    Colr = Rnd * &HFFFFFF
    radius = Rnd * ScreenWidth / 400 * Size * Size
    canvas.FillColor = Colr
    canvas.FillStyle = vbFSSolid
    canvas.Circle (x, Y), radius, Colr
End Sub

Ideally you place a timer on the form that will be used to make the drawings, and place there the draw routine and this way you don't need to use the "DoEvents" function.

Private Sub Timer1_Timer()
    Draw Me
End Sub

The other possibillity is placing a endless loop when the form is made visible and the put some code like this.

Do
    Draw Me
    DoEvents
Loop While Status=1

-------------
Status is a global flag that is equal to 0, and you set it to 1 whenever you want to screensaver to terminate

trillo
0
 

Author Comment

by:rscptn
ID: 1448076
Would you clarify for me how to use the keypress and mouse click events to trigger the doevent and switch between two screen savers and a password screen.
Thanks
0
 
LVL 2

Expert Comment

by:trillo
ID: 1448077
I Can guess that you're not very familiar with the doEvents function so i'll expalin.
Supose you have and pseudo infinite loop such as next example, and supose your code provides a "Cancel" button to stop the loop.
When the user presses the cancel button, you set a flag to True.

Dim SomeFlag as Boolean

Private Sub Cancel_Click()
    SomeFlag = True
EndSub

' Let's say your loop looks like
While someflag = False do
    SomeFunction()
Loop

This code doesn't work because when you enter the loop, you'll never get out of it, because YOU DON'T GIVE A CHANCE TO THE CANCEL BUTTON TO BE PRESSED, meaning that the Flag will never change. The execution will remain in the loop, so the code for the cancel button will never be reached. That is the purpose of the DoEvents function.

' Now the loop looks like
While someflag = False do
    SomeFunction()
    DoEvents
Loop

Here, the DoEvents function allows the program to execute pending tasks (such as the code in the cancel button), and when all other tasks are done, DoEvents returns.

Now let's go back to the ScreenSaver.
Your loop, somewhere in Form1 looks like
.....
   While someflag = False do
       UpdateScreenSaver()
       DoEvents
   Loop
   Form2.show
   Unload Me

Private Sub form1_MouseMove(...)
    someflag=True
End Sub

Here's how it works, you will update teh ScreenSaver, then are calling DoEvents, this will check all pneding tasks, for example the mousemove event. If the user has not move the mouse, someFlag will still be False and your loop will Update the ScreenSaver again, and so forth. when the user moves the mouse, the screen saver stops because your SomeFlag is now True. this will pass the execution to the next line, loading form2 and unloading Form1.

On form2, you place a similar code to show the PassWord Screen.

If you still have questions, tell me.
Trillo
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

770 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