Solved

When to use the Refresh method

Posted on 2003-12-08
6
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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
Comment Utility
Just

stbStatusBar.Refresh
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now