Progress bar

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
hip2b2
Newbie
Posts: 9
Joined: Thu Nov 05, 2009 4:41 am

Progress bar

Post by hip2b2 » Mon Mar 14, 2011 5:10 pm

I have modified in a small way the sample progress bar script (included below). I have 2 problems in getting this script to do what I need:

1 - Start script counter on open (i.e., remove the "Start" button). I know what part of the script to remove to get rid of the start button, but I would like to include this script within another MS script and so have the counter start on script open.

2 - I believe that number of total length of progress is set by the width of the window? If my time units ("wait>" is equal to 60 seconds, then I need to make the window width equal to 60 units wide to equal an hour. Is this correct?

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Dialog>Dialog1
object Dialog1: TForm
  Left = 576
  Top = 266
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Progress Bar Example'
  ClientHeight = 100
  ClientWidth = 539
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object ProgressBar1: TProgressBar
    Left = 19
    Top = 17
    Width = 499
    Height = 17
    TabOrder = 8
  end

 object btnStart: tMSButton
   Left = 24
   Top = 56
   Width = 75
   Height = 25
   Caption = 'Start'
   DoubleBuffered = True
   ParentDoubleBuffered = False
   TabOrder = 9
   DoBrowse = False
   BrowseStyle = fbOpen
  end
 
  object btnClose: tMSButton
    Left = 440
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Close'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 12
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

//AddDialogHandler>Dialog1,btnStart,OnClick,DoProgress
AddDialogHandler>Dialog1,btnClose,OnClick,DoClose

GetDialogProperty>Dialog1,ProgressBar1,Min,intMin
GetDialogProperty>Dialog1,ProgressBar1,Max,intMax

Let>k=intMin

Show>Dialog1,r

If>r=2
  Exit>0
Endif


SRT>DoProgress
//  SetDialogProperty>Dialog1,btnStart,Enabled,False
  Let>k=intMin
  Repeat>k
    Let>k=k+1
    SetDialogProperty>Dialog1,ProgressBar1,Position,k
    Wait>0.05
  Until>k=intMax
  SetDialogProperty>Dialog1,btnStart,Enabled,True
END>DoProgress

SRT>DoClose
  Let>k=intMax
END>DoClose

        adroege
        Automation Wizard
        Posts: 438
        Joined: Tue Dec 07, 2004 7:39 pm

        Post by adroege » Mon Mar 14, 2011 9:20 pm

        Here is a simpler example for you. It starts as soon as the script starts. Normally you update a progress bar as code in your program executes. Here it is updated all in one loop. Change the increment amount, wait, etc to suit your situation.

        Code: Select all

          //Progress bar dialog
        Dialog>dlgProgress
           Caption=Progress
           Width=451
           Height=67
           Top=CENTER
           Left=CENTER
           Max=0
           Min=0
           Close=0
           Resize=0
           progressbar=bar1,0,8,441,16,0
        EndDialog>dlgProgress
        
        
          Let>dlgProgress.bar1=1
          Show>dlgProgress
        
        Let>k=0
        Repeat>k
          Add>k,1
          Wait>0.5
          // do stuff
          //  ...
          //  ...
          
          // now update the progress bar
          Add>dlgProgress.bar1,1
          ResetDialogAction>dlgProgress
        Until>k=100
        
        

        User avatar
        JRL
        Automation Wizard
        Posts: 3526
        Joined: Mon Jan 10, 2005 6:22 pm
        Location: Iowa

        Post by JRL » Mon Mar 14, 2011 9:50 pm

        1 - Start script counter on open (i.e., remove the "Start" button). I know what part of the script to remove to get rid of the start button, but I would like to include this script within another MS script and so have the counter start on script open.
        The script pauses for user input at the dialog because the dialog is "Modal". See Marcus' Blog modal-vs-non-modal-windows-not-jazz

        To make the dialog non-modal you simply remove the result variable from the Show> function.

        Show>Dialog1,r
        Becomes
        Show>Dialog1

        Then the dialog needs to proceed on to a loop. The repeat portion of the "DoProgress" subroutine could serve as that loop. But you will need to add a GoSub>DoProgress to go to the subroutine.

        2 - I believe that number of total length of progress is set by the width of the window? If my time units ("wait>" is equal to 60 seconds, then I need to make the window width equal to 60 units wide to equal an hour. Is this correct?
        No

        The progress bar width is whatever you want it to be though you probably want the dialog to be wider than the progress bar it does not need to be. You can set the number of ticks for the progress bar by setting the "Max" Progress Bar object property. In your case you might want to set "Max" to 60. And if you want to wait approximately 60 seconds you probably want the Wait in the Repeat loop to be about 1 second.

        I see that adroege has already posted a simpler script for you but here is the same script you posted simplified.

        Code: Select all

        Dialog>Dialog1
        object Dialog1: TForm
          Left = 576
          Top = 266
          HelpContext = 5000
          BorderIcons = [biSystemMenu]
          Caption = 'Progress Bar Example'
          ClientHeight = 100
          ClientWidth = 539
          object ProgressBar1: TProgressBar
            Left = 19
            Top = 17
            Width = 499
            Height = 17
          end
         object btnClose: tMSButton
            Left = 440
            Top = 56
            Width = 75
            Height = 25
            Caption = 'Close'
          end
        end
        EndDialog>Dialog1
        
        AddDialogHandler>Dialog1,btnClose,OnClick,DoClose
        SetDialogProperty>Dialog1,ProgressBar1,Max,60
        Show>Dialog1
        
        GoSub>DoProgress
        
        SRT>DoProgress
          Let>k=0
          Repeat>k
            Let>k=k+1
            SetDialogProperty>Dialog1,ProgressBar1,Position,k
            Wait>1
          Until>k=60
          SetDialogProperty>Dialog1,btnStart,Enabled,True
        END>DoProgress
        
        SRT>DoClose
          Exit>0
        END>DoClose
        

        hip2b2
        Newbie
        Posts: 9
        Joined: Thu Nov 05, 2009 4:41 am

        Post by hip2b2 » Tue Mar 15, 2011 10:39 am

        Many thanks for the help. I THINK / hope that does it.

        Regards

        hip

        User avatar
        JRL
        Automation Wizard
        Posts: 3526
        Joined: Mon Jan 10, 2005 6:22 pm
        Location: Iowa

        Post by JRL » Fri Mar 18, 2011 4:39 am

        Just because we can.

        In contrast to the simplified progress bar examples, here is a more complicated use of a couple of progress bars. Who knew that in version 12 you can have a vertical progress bar?

        Code: Select all

        Dialog>Dialog1
        object Dialog1: TForm
          Left = 286
          Top = 179
          BorderStyle = bsNone
          Caption = 'Vertical Progress Bar'
          ClientHeight = 436
          ClientWidth = 395
          Color = 0
          Position = poScreenCenter
          TransparentColor = True
          object ProgressBar1: TProgressBar
            Left = 20
            Top = 45
            Width = 15
            Height = 340
            Orientation = pbVertical
            BackgroundColor = 0
            BorderWidth = -1
          end
          object ProgressBar2: TProgressBar
            Left = 20
            Top = 385
            Width = 350
            Height = 15
            BackgroundColor = 0
            BorderWidth = -1
          end
          object Panel1: TPanel
            Left = 51
            Top = 53
            Width = 289
            Height = 321
            Color = 0
            BevelWidth = 0
          end
        end
        EndDialog>Dialog1
        Dialog>Dialog3
        object Dialog3: TForm
          BorderStyle = bsNone
          Caption = 'Display Bars'
          ClientHeight = 436
          ClientWidth = 395
          Color = 0
          Position = poScreenCenter
          TransparentColor = True
        end
        EndDialog>Dialog3
        Show>Dialog1
        Show>Dialog3
        Let>WIN_USEHANDLE=1
          MoveWindow>Dialog1.handle,-32000,0
        Let>WIN_USEHANDLE=0
        
        LibFunc>user32,GetDC,HDC1,Dialog1.handle
        LibFunc>user32,GetDC,HDC3,Dialog3.handle
        
        Let>kk1=0
        Let>gColor=20
        Let>rColor=250
        Repeat>kk1
          Add>kk1,1
          Add>gColor,2
          Sub>rColor,2
          RGB>rColor,gColor,0,vColor
          SetDialogProperty>Dialog1,ProgressBar1,BarColor,vColor
          SetDialogProperty>Dialog1,ProgressBar2,BarColor,vColor
          SetDialogProperty>Dialog1,ProgressBar1,Position,kk1
          SetDialogProperty>Dialog1,ProgressBar2,Position,kk1
            LibFunc>Gdi32,StretchBlt,SBres,HDC3,20,45,15,340,HDC1,20,45,15,340,13369376
            LibFunc>Gdi32,StretchBlt,SBres,HDC3,20,385,350,15,HDC1,20,385,350,15,13369376
            LibFunc>Gdi32,StretchBlt,SBres,HDC3,370,385,-15,-340,HDC1,20,45,15,340,13369376
            LibFunc>Gdi32,StretchBlt,SBres,HDC3,370,30,-350,15,HDC1,20,385,350,15,13369376
          Wait>0.03
        Until>kk1=100
        
        Wait>1
        SetDialogProperty>Dialog1,Panel1,Color,vColor
        SetDialogObjectFont>Dialog1,Panel1,Arial,40,1,16777215
        SetDialogProperty>Dialog1,Panel1,Caption,Complete
        LibFunc>Gdi32,StretchBlt,SBres,HDC3,51,53,289,321,HDC1,51,53,289,321,13369376
        Wait>3
        

        User avatar
        jpuziano
        Automation Wizard
        Posts: 1085
        Joined: Sat Oct 30, 2004 12:00 am

        Post by jpuziano » Fri Mar 18, 2011 4:19 pm

        JRL wrote:Who knew that in version 12 you can have a vertical progress bar?
        Probably not many of us until now - thanks for sharing that verticle progress bar example script... nice effect with the 4 progress bars growing to form a complete square. And, I take it that if the progress bar really slowed down because whatever process it was displaying the progress of became really slow... the color of the progress bar would still continue to change at the same pace to reassure the user that the script isn't locked up... just slow... that in itself is a great feature. And then when its done you pop a huge "Complete" in the middle with a solid green background that's big enough to be seen from quite a ways away... perhaps across a machine shop floor.

        Nicely done, thanks again JRL.
        jpuziano

        Note: If anyone else on the planet would find the following useful...
        [Open] PlayWav command that plays from embedded script data
        ...then please add your thoughts/support at the above post - :-)

        Post Reply
        cron
        Sign up to our newsletter for free automation tips, tricks & discounts