Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using a doevent with a screen saver

Posted on 1998-12-03
3
Medium Priority
?
253 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

971 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