Board Logo
« progress bar in main window »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:36pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: progress bar in main window  (Read 320 times)
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 268
xx progress bar in main window
« Thread started on: Feb 16th, 2017, 1:17pm »

A simple Progress Bar in Main window
Code:

    x=5
    y=5
  n=200
      locate x,y-2
      print "   proccessing..."
    locate x,y
       print 0;"%"
  for i=1 to n
         k=int(n/10)
   if i mod k=0 then
         locate x,y
         print int(i*100/n);"%"
         t=t+1
        locate x+5+t,y:print"=>"
    end if
       if i=1 then locate x+5,y:print"<": locate x+6,y:print">"
   timer 50,[t1]
     wait
     [t1]
   timer 0
 next
 locate x,y-2 :print space$(20)
 locate x+10+t,y: print" succes"

 
User IP Logged

AndyAmaya
Board Moderator


member is offline

Avatar




PM

Gender: Male
Posts: 362
xx Re: progress bar in main window
« Reply #1 on: Feb 16th, 2017, 3:00pm »

Nicely done zzz000abc!

It may be better to wrap your code in a function or sub to give you even more flexibility. As a function or sub you can reuse your code in any future project.

Here's an example of 'sbar' SUB (status bar sub) shown in this thread last code box of initial post
It shows how to display multiple progress/status bars all at the same time. ;)

Code:
Print "Multiple Status Bar SUB example"

For i = 2 To 100 Step 2
    'Top status bar
    Locate 42, 2
    Print Using("###",i);"%"
    '    sBar xLoc, yLoc, bar$, barMax, pct
    Call sBar 9,    3,    "|",  70,     i

    'Middle status bar
    Locate 30, 7
    Print Using("###",i);"%"
    '    sBar xLoc, yLoc, bar$, barMax, pct
    Call sBar 9,    8,    "0",  50,     i

    'Bottom status bar
    Locate 15, 12
    Print Using("###",i);"%"
    Call sBar 9, 13,">", 15, i

    Call pause 100
Next
end


Sub sBar xLoc, yLoc, bar$, barMax, pct
    'xLoc, yLoc define the location of upper-left corner of status bar
    'bar$ is the character used to display inside status bar
    'barMax is the maximum number of characters to display 100%
    'pct is the percentage to display in status bar

    showBox = 0 '<---Change to 1 to display status change inside of box

    boxLen = barMax + 2
    For i = 1 To barMax
        dash$ = dash$ + "-"
        in$ = in$ + bar$
    Next
    If pct > .999 Then frac = pct/100.0
    show$ = Left$(in$, Int(frac*barMax))
    If Len(show$) = barMax Then
        blank$ = ""
    Else
        blank$ = Space$(barMax-Len(show$))
    End If
    Locate xLoc, yLoc
    If showBox = 1 Then Print ""+dash$+""
    If showBox = 1 Then
        Locate xLoc, yLoc+1
    Else
        Locate xLoc, yLoc
    End If
    Print "["+show$+blank$+"]"
    Locate xLoc, yLoc+2
    If showBox = 1 Then Print ""+dash$+""
End Sub

Sub pause ms
    Timer ms, [timerOff]
    Wait
    [timerOff]
    Timer 0
End Sub
 
« Last Edit: Feb 16th, 2017, 3:02pm by AndyAmaya » User IP Logged

zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 268
xx Re: progress bar in main window
« Reply #2 on: Feb 18th, 2017, 10:12am »

thank you Andy Amaya for suggestions
here is the function pbar() along with two usage examples.
Code:
' t=pbar(m$,n$,x,y,f,l,p,d,t)
'msg1$- first message
'msg2$-last message
'x&y - column and row
'f&l - first and last values
'p- present/current value
'd-number of divisions
't- temperory variable
'* timer is not necessary always.It is used in the following examples
'  to delay the process and for demonstration purpose only.
'example 1
     x=5
      y=5
     d=16
    m$="proccessing"
    n$="Success"

  for i=5 to 173 'increasing i
      ss=pbar(m$,n$,x,y,5,173,i,d,ss) 'note the usage of ss it should be same at both the places
      k=k+1
    timer 20,[t1]
    wait
    [t1]
   timer 0
 next
 input "enter any key to continue";a
 cls
'example 2
p =30
  fact=1
  for i=p to 1 step -1 'decreasing i
      tmp=pbar("please wait","completed",5,5,30,1,i,10,tmp)
      ' note the usage of tmp it should be sameat both the places
      fact=fact*i
     timer 100,[t2]
     wait
     [t2]
     timer 0
  next
  print
  print "factorial =";fact

 'example 3


'--------------------------------------------------------------------------

 function pbar(msg1$,msg2$,x,y,f,l,p,d,t)
           if f=l then pbar=0
          if f>l then tmp=l:l=f:f=tmp:p=l+f-p':print p
      k=int(l/d)
    if p mod k=0 then
         locate x,y
         print int(p*100/l);"%"
         t=t+1
        locate x+7+t,y
        print"=>" 'inplace of '=' you can use any other symbol like '+' or '@' etc.
    end if
       if p=f then
              locate x+7,y:print"<": locate x+9,y:print">"
                locate x,y-2
               print msg1$
           locate x,y
           print 0;"%"
      end if

    if p=l then
          locate x,y-2 :print space$(len(msg1$)+10)
           locate x+10+t,y+1: print space$(4)+msg2$
   end if
     pbar=t
  end function
 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls