Solved

using a doevent with a screen saver

Posted on 1998-12-03
3
233 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 100 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 54
Determine Range to Select 5 48
Zip Folders Using Chilkat Routines 1 39
Excel Automation VBA 19 69
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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