INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

How can I make a Progress Bar? by BlindPete
Posted: 6 Sep 00 (Edited 1 Jan 04)

This is a class that will display a progress bar and allows you to cancel a process.  It is fairly simple to use and implement.  If you make any significant changes to this class.  Please send them along to me.


*EXAMPLE
oPB = CREATEOBJECT("PROGRESSBAR","Title","Caption ")
*"Title" and "Caption " are Optional Paramaters
oPB.counter = 0
oPB.show
FOR x = 1 to 100 STEP +.01
  IF TYPE('oPB.ButtonCancel')<>'U' THEN &&Cancel pushed?
    oPB.counter = x
  ELSE
    x=101
  ENDIF
NEXT x
IF TYPE('oPB.ButtonCancel')<>'U' THEN &&still exists?
  oPB.Release
ENDIF



DEFINE CLASS "Progressbar" AS "FORM"
  COUNTER = 0.5
  BarCaption = ""
  ButtonCancel =.F.
  ALWAYSONTOP = .T.
  AUTOCENTER = .T.
  SHOWWINDOW = 2 && top level form
  WINDOWTYPE = 1 && Modal
  DRAWMODE = 9
  TITLEBAR = 1
  CONTROLBOX = .F.
  HEIGHT = 83
  WIDTH = 264+24
  
  ADD OBJECT "oTxt" AS "TEXTBOX" WITH ;
    HEIGHT = 25, LEFT =12, WIDTH = 264, ALIGNMENT = 2, ;
    TOP = 6, BACKCOLOR = RGB(255,255,255), ;
    DISABLEDBACKCOLOR = RGB(255,255,255), ;
    DISABLEDFORECOLOR = RGB(0,0,0), ;
    ENABLED = .F., FONTBOLD = .T.
    
  ADD OBJECT "oCmd1" AS "COMMANDBUTTON" WITH ;
    CAPTION = "\<Cancel", HEIGHT = 25, LEFT = 96, ;
    WIDTH = 97, TOP = 48
    PROCEDURE oCmd1.CLICK
      nQuit = MESSAGEBOX('Are you sure you want to cancel?',4+32,thisform.caption)
      If nQuit = 6 THEN
        thisform.ButtonCancel =.T. &&abort search
        thisform.release
      ENDIF
    ENDPROC
    
  ADD OBJECT "oShp" AS "SHAPE" WITH ;
    BORDERSTYLE = 0, DRAWMODE = 14, FILLSTYLE = 0
    
  PROCEDURE INIT
    PARAMETER cCaption, cBarCaption
    IF EMPTY(cCaption) THEN
      cCaption = ""
    ENDIF
    IF EMPTY(cBarCaption) THEN
      cBarCaption = ""
    ENDIF
    thisform.oshp.left=thisform.oTxt.left+1
    thisform.oshp.top=thisform.oTxt.top +1
    thisform.oshp.height=thisform.oTxt.height-2
    thisform.oshp.visible = .T.
    thisform.borderstyle = 2
    thisform.caption = cCaption
    thisform.BarCaption = cBarCaption
  ENDPROC
  
  PROCEDURE Counter_assign
    LPARAMETERS vNewVal
    IF vNewVal <> thisform.counter THEN
      IF vNewVal > 100 THEN
        vNewVal = 100
      ENDIF
      thisform.counter = vNewVal
      x = thisform.counter
      thisform.oShp.width = x*thisform.oTxt.width/100
      thisform.oTxt.value = thisform.BarCaption+ALLTRIM(STR(x))+"% Complete"
      thisform.refresh
      *Check if cancel button has been pushed Alt+C or clicked
      IF MDOWN() OR CHRSAW() THEN
        DOEVENTS
      ENDIF
    ENDIF
  ENDPROC
  
ENDDEFINE
*EOF

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close