Solved

When to use the Refresh method

Posted on 2003-12-08
6
252 Views
Last Modified: 2010-05-01
When does one know when to use the Refresh method of a form or control?  I've seen sample code where it's used quite a bit.  As a test, I've removed them and the application still seems to work fine.

Thanks.
0
Comment
Question by:halfondj
6 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9898556
REfresh is used to forces a complete repaint of a form or control.


If you have do a lot inside the routine and you want to refresh the form or control, then you need to use refresh

ie.

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Text1.Text = Now
Text1.Refresh
Sleep 3000
End Sub


without the refresh the time will show 3 seconds later
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9898557
For example ,
I have a flexgrid which can have several 100 to 1000 items loaded into it ...If you have autoredraw=true then the grid will run extremely slow as it is trying to redraw itself every time any modification is made , in my case I am talking around 30 seconds ... If you turn autoredraw=false then the grid doesnt try to redraw itself until you call the refresh method when I am finished with all my updates to the grid...
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9898632
Arghh, Make that the redraw property rather....My memory played a trick on me , went back to verify and I was remembering redraw rather than refresh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9901138
You need to use either Refresh or call DoEvents from within a looping structure that updates visual components during each iteration as VB does not update the screen until all code has completed.  Only do this if immediate feedback is required as it does slow down execution significantly.

Idle_Mind
0
 

Author Comment

by:halfondj
ID: 9903887
After setting the status bar, e.g.

     stbStatusBar.Panels(1).Text = "Ending communications session."

How would one refresh the status bar?  I get compile errors when trying:

    stbStatusBar.Panels(1).Text.Refresh

Thanks.
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 9903994
Just

stbStatusBar.Refresh
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now