Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Keana Schmidt   on Oct 20 In MS Office Category.

  
Question Answered By: Malcolm Carter   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

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

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


Tagged: