Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Userform ( .Repaint ) ?

  Asked By: Keana    Date: Oct 20    Category: MS Office    Views: 19300
  

What is the main purpose for doing the ( .Repaint ) for a Userform ?

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Pearl Garza     Answered On: Oct 20

If you update the text for a control caption or text property, using the
Repaint method causes the form to refresh the control contents to the
screen. This is especially handy when you've built things like a progress
bar and are doing lots of automated processing. The normal thing to happen
in this instance is that form repaints are done as opportunity presents.
Using the repaint  method means that you sacrifice a little speed to force
the graphics engine to update the appearance of the form and update the
visible contents of the form's child controls as seen by your customer.

 
Answer #2    Answered By: Finn Jones     Answered On: Oct 20

I use it to display a PROGRESS BAR when I'm updating a project that may take
a little time...to help the user see that SOMETHING is going on while they
wait.

If you look here:
www.mousetrax.com/Consulting_Solutions.html, and scroll down,
you'll see that as the employee review is doing it's thing to compile, I
display a progress bar. That bar is a tiny user form with a textbox inside
that is colored blue.

As various steps within the main  code runs, the bar code is hit and makes
the colored textbox a little longer...and thereby repaints the display so
the new length of the blue textbox displays an updated view of the newly
lengthened textbox.

As things move along quickly in the code, the textbox continually lengthens
and displayed the new, repainted version, on the screen...thereby giving the
illusion that the progress bar is moving along as the code behind in the doc
does it's job.

 
Answer #3    Answered By: Hiroshi Yoshida     Answered On: Oct 20

How does one calculate the 0% to 100% for the ProgressBar ?
From what I have seen thus far, is hardcoding
the 0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100%
for each ProgressBar statement...( sigh )

An application can consist of 100 modules/subroutines.
Which means, the person coding the application has to know the
exact flow path from module/subroutine TO module/subroutine...( sigh )

Is there a better method in place to calculate the %(percentage), instead
of hardcoding the %(percentage) as the module/subroutine is being called.

 
Answer #4    Answered By: Eustatius Bakker     Answered On: Oct 20

Search the web, I'm sure you can find an algorithm for it.

 
Answer #5    Answered By: Ismet Yilmaz     Answered On: Oct 20

I've built this into the MouseTrax File Cataloger tool at
http://www.mousetrax.com/downloads.html. The code for the progress bar,
calculating percentage and updating the progress bar is all ready for open
and indiscreet theft at your leisure. And it will work in Excel as easily as
in Word. It's clean and accurate. Tasty, in fact.

 
Answer #6    Answered By: Malcolm Carter     Answered On: Oct 20

In fact, here's the code for the userform, frmProgress, which has 3
controls. cmdCancel(Cancel button), lblPercent(a label) and lblStatus(where
I put messages about the current operation being performed):

'**********************************************************************
Private Sub cmdCancel_Click()

BoolCancel = True
Me.Hide
Unload Me
Exit Sub

End Sub
'**********************************************************************
Private Sub lblPercent_Click()

End Sub
'**********************************************************************
Private Sub lblStatus_Click()

End Sub
'**********************************************************************

The labels are 288 pixels wide and the form is 304.5 pixels wide. The Form's
ShowModal property is false.

Code to calculate percentage (Put this in a code module):
'**********************************************************************
Sub ShowProgress(ByVal snglFileCounter, ByVal snglCount, _
ByVal strFolderPath As String)

Dim snglDecimal As Single
Dim snglWidth As Single
Dim strLabelText As String

If BoolCancel Then Exit Sub

snglDecimal = snglFileCounter / snglCount
snglWidth = snglDecimal * 280
strLabelText = TruncPathForLabel(strFolderPath)

frmProgress.lblPercent.Caption = "Folder scan is " & _
FormatPercent(snglDecimal) & " complete."
frmProgress.lblStatus.Caption = snglCount & " files in " & strLabelText
frmProgress.lblProgress.Width = snglWidth
frmProgress.Repaint

End Sub
'**********************************************************************

And how to call it:
ShowProgress (TotalNumber_Of_Items, Number_Of_Current_Item,
String_For_Status_Label)

This progress counter is obviously aimed at file counts and processing but
it's very portable for other purposes without modification. In fact, you can
make the strFolderPath argument optional if you're only wanting to show the
progress bar mercury run from left to right.

Here's a little sample routine which would work as a test:
'**********************************************************************
Sub TestProgress()

Dim I as Integer
Dim intLimit as Integer

frmProgress.Show
intLimit=10000
For I= 0 to intLimit
ShowProgress intLimit, I, "Processing item " & _
CStr(I) & " of " & CStr(intLimit)
Next i
frmProgress.Hide

End Sub

 
Answer #7    Answered By: Joann Gardner     Answered On: Oct 20

So, it helps to not work from memory. Here are the last details and a couple
corrections:
- Another label is required on the form called lblProgress. Set this label
to 0 pixels wide, Left at 6 pixels, background color set to Highlight
- Set the Form's width to 304.5 pixels

Use the following code:
'********************************************************
Sub TestProgress()

Dim I As Integer
Dim intLimit As Integer

frmProgress.Show
intLimit = 10000
For I = 1 To intLimit
ShowProgress I, intLimit, "Processing item " & _
CStr(I) & " of " & CStr(intLimit)
Next I
frmProgress.Hide

End Sub
'**********************************************************
Sub ShowProgress(ByVal snglFileCounter, ByVal snglCount, _
ByVal strFolderPath As String)

Dim snglDecimal As Single
Dim snglWidth As Single
Dim strLabelText As String

If BoolCancel Then Exit Sub

snglDecimal = snglFileCounter / snglCount
snglWidth = snglDecimal * 280
strLabelText = strFolderPath
frmProgress.lblPercent.Caption = strFolderPath
frmProgress.lblStatus.Caption = snglCount & _
" Items in " & strLabelText
frmProgress.lblProgress.Width = snglWidth
frmProgress.Repaint

End Sub
'*********************************************************

The idea is to have a small label with a distinct background color. Each
time you call the routine, you're giving values from which a percentage is
calculated and lblProgress, with its dsitinctive color, is made wider to
correspond with your progress from 0 to 100%. The percentage calculation is
exactly what we were taught in school - to get the percentage of elements
from a big pile of elements, divide the number of the item you're working
with and divide by the total number of elements. That percentage is then
multiplied by the maximum width of lblProgress (280) to determine just how
many pixels wide lblProgress should be if we're only at, say, 49%.

Use this code in frmProgress itself:
Private Sub cmdCancel_Click()

BoolCancel = True
Me.Hide
Unload Me
Exit Sub

End Sub

 
Didn't find what you were looking for? Find more on Userform ( .Repaint ) ? Or get search suggestion and latest updates.




Tagged: