stdVBA icon indicating copy to clipboard operation
stdVBA copied to clipboard

stdProgress

Open sancarn opened this issue 3 years ago • 0 comments

stdProgress

Concept

The concept is to be able to build a Progress object, which can continuously sub-divide progress (and ultimately update a progress bar). This progress object could also be supplied as a parameter to functions which increases the ease of using it as a progress meter.

Example 1:

With stdProgress.CreateFromPercents(0.9,0.1).bindForm(myProgressBar)
  Dim allSheetNames as collection: set allSheetNames = new collection
  With .CreateFromCount(workbooks.count)
    For each wb in workbooks
      With .CreateFromCount(wb.sheets.count)
        for each sheet in wb.sheets
          allSheetNames.add sheet.name
          .step
        next
      End With
    next
  End With
  With .CreateFromCount(allSheetNames.count)
      Dim vSheetName
      for each vSheetName in allSheetNames
        debug.print vSheetName
        .step
      next
  End with
End With
  1. We divide the work into a 0.9 and 0.1 split, i.e. 90% and 10%.
  2. We subdivide the 90% into workbook.count parts. Assume 2 workbooks are open, so that's 45% each.
  3. We subdivide the 45% into wb.sheets.count parts. Assume 5 sheets per workbook so 9% per sheet.
  4. We step for every sheet name added to the workbook incrementing up the tree till the parent, which updates the form.
  5. Upon finishing we've updated 90% of the progress, 10% remains
  6. We divide this 10% into the number of sheets (10) so 1% for each sheet.
  7. Each sheet we increment by this value
  8. We unload the object as progress is completed

Example 2

With stdProgress.CreateFromCount(3)
  'do some task
  .step()
  'do some other task
  .step()
  'do some other task
  .step() 'optional, as the progress bar will unload immediately after this method in this case
End With

Example 3

Sub test(pb)
  with pb.CreateFromCount(workbooks.count)
    for each wb in workbooks
      if wb.name = sName then
        debug.print workbook.fullname
        pb.finish
        exit function
      end if
    next
  end with
End Sub

Spec

  • [ ] Constructors
    • [ ] stdProgress::CreateFromPercents(Paramarray params())
    • [ ] stdProgress#CreateFromPercents(Paramarray params())
    • [ ] stdProgress::CreateFromCount(iPartsCount as long)
    • [ ] std{rpgress#CreateFromCount(iPartsCount as long) - split progress evenly amongst N parts
    • [ ] self - Returns Me
  • [ ] Instance methods
    • [ ] bindForm(Optional Byval oUF as object, ByVal sUpdateMethodName as string) - binds a form with an update method, if no form supplied just return self
    • [ ] bindFrame(Optional ByVal fr as frame) - binds a frame, the progress object will insert labels into the frame to visualise progress. If no fram supplied just return self
    • [ ] Step - steps forward by 1 step of progress. Default is 0.01 if created from percents, otherwise it's 1 from counts.
    • [ ] Finish - call if you need to urgently finish the progress accumulated.

sancarn avatar Jul 22 '21 16:07 sancarn