?
Solved

Give it Some Time to Relax

Posted on 2000-03-23
7
Medium Priority
?
203 Views
Last Modified: 2010-05-02
I often write code that force my computer to process a huge amount of data.  In these cases, the computer seems to allocate all its ressources to this hungry operation, forgetting to refresh the new screen display.
For instance, in the program I am currently building, I press a button which does the following tasks:
- Change my mousepointer to hourglass;
(screen.mousepointer = vbhourglass)
- Make a grid invisible;
(msgWhatever.visible = false)
- Process heavy data.

The problem is: the processor never allow my mouse cursor to change, nor the grid to become invisible.  I seek a clean and efficient way to give some processor time to these others simple visual tasks.  For now, I'm stuck with DOEVENTS, which works SOMETIMES.  Am I using this function the wrong way?
0
Comment
Question by:Sylvania
[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
7 Comments
 
LVL 1

Accepted Solution

by:
pclement earned 225 total points
ID: 2650128
Doesn't sound like it. Sometimes DoEvents needs to be placed somewhat strategically in code so you may need to play a bit to see what works best.

If you are having repainting difficulties you also may want to try using the Refresh method prior to executing resource intensive code.

Ultimately DoEvents is a rather inefficient method for handling these type of problems, so be judicious in your usage.

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2650150
"DoEvents" allows your program to dispatch any other outstanding tasks and then pickup where it left off.  You need to plan where you are putting "DoEvents" very carfully...  

For example, you could get into a situation where the user clicks a button to start a loop that has a "DoEvents" in it. While the loop is executing, if the user clicks the same button again, you will start 2 iterations of the loop... VERY BAD!

What you may also want to consider is calling the Refresh Event of controls that have it... for example, explicitly calling:

   Grid1.Visible = True
   Grid1.Refresh


Cheers!®©
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2650158
I could put down a long explanation, but an example is better.

Start a new project with two forms. But a command button on form2.

Paste the following in Form1
Option Explicit

Private Sub Form_Load()

Load Form2
Form2.Show vbModeless

End Sub


Paste the following in Form2
Option Explicit
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()

Form2.Visible = False
'SetCursorPos (Form1.Left + Form1.Width / 2) / Screen.TwipsPerPixelX, (Form1.Top + Form1.Height / 2) / Screen.TwipsPerPixelY
Form1.MousePointer = vbHourglass
DoEvents
Dim lngCounter As Long
For lngCounter = 1 To 10 ^ 8
Next
Form1.MousePointer = vbDefault
Form2.Show vbModeless

End Sub


NB: Do keep the setcursorpos statement commented out for the moment.

You may have to adjust the value 10 ^ 8 according to the speed of your computer. Choose something that does something for a couple of seconds but doesn't leave you waiting for minutes ;-)


Start the program.

Click on Form2.

1 - Make sure that Form2 is positioned over Form1. Specifically, the command button should be well over Form1
Click the button. Everything's fine. The hourglass appears.

2 - Move Form2 well away from Form1 so there's no overlap. Click the button. Now the mousepointer does not change. Not even when you move the mouse over Form1.

3 - To fix this problem, uncomment the SetCursorPos statement.

I cannot say for definite, but maybe your problem is caused by something similar.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2650175
The following would be even cleaner as the cursor seems to stay in the same location:

replace Form2 code with this:

Option Explicit
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


Private Sub Command1_Click()

Dim cPos As POINTAPI
GetCursorPos cPos
Form2.Visible = False
SetCursorPos (Form1.Left + Form1.Width / 2) / Screen.TwipsPerPixelX, (Form1.Top + Form1.Height / 2) / Screen.TwipsPerPixelY
Form1.MousePointer = vbHourglass
DoEvents
SetCursorPos cPos.x, cPos.y
Dim lngCounter As Long
For lngCounter = 1 To 10 ^ 8
Next
Form1.MousePointer = vbDefault
Form2.Show vbModeless

End Sub
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2653641
From the lack of response I gather that that worked for you then?
0
 

Author Comment

by:Sylvania
ID: 2653825
No, I'm sorry.  My question wasn't about mouse cursor: it was about processor time dealing.  I was trying to find if someone had a better way to give some processor time to lighter tasks while heavy ones were going on their own; the mousepointer was only an example, like the msflexgrid.visible thing.
0
 

Author Comment

by:Sylvania
ID: 2654946
I guess this would shut this question.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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

649 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