Text progress bar

General FreeBASIC programming questions.
Post Reply
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Text progress bar

Post by Gablea »

Hi everyone,
I have been given code from a very smart person on here code to download files from my server to the local machine with a graphical display Progress bar.

It is possible to use the progress bar in text mode only as I would like to make a app for a small dos till, the user only has a 2x20 chr Display no graphical display and the system is running FreeDOS.

|—————————————-|
| dloading product.dat |
|10% |||————————- |
|—————————————-|

Is it possible to do “progress bar” on the 2x20 chr line display or should I just have it say

Hope I’ve explained myself enough if not I can upload the copy function.

Andy

|—————————————-|
| DOWNLOADING.. |
| products.dat 10% |
|—————————————-|
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Text progress bar

Post by Boromir »

There isn't much difference between the code for a graphical progress bar and the code for a console bar. What part is giving you trouble?
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Text progress bar

Post by badidea »

Can you use character background color?
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Text progress bar

Post by Boromir »

Here is a quick example of a console percentage bar.

Code: Select all

dim as integer currentamount,totalamount=250,percentage

'console progress bar
do
cls
currentamount+=1
percentage=(currentamount*100)\totalamount
print str(percentage)+"%  :"
for j as integer=0 to 10
	if j<=(percentage\10) then
		print "=";
	else
		print "-";
	end if
next
print ""

sleep 10,1
loop until currentamount=totalamount


print "press any key to continue"
sleep

'graphical progress bar
currentamount=0
screen 18,32

do
cls
currentamount+=1
percentage=(currentamount*100)\totalamount
print str(percentage)+"%  :"
line(0,20)-(100,30),rgb(255,0,0),bf
line(0,20)-(percentage,30),rgb(0,255,0),bf
print ""

sleep 10,1
loop until currentamount=totalamount


print "press any key to continue"
sleep
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Post by Gablea »

The only thing I can do is display text in the screen (it is a small 2 line display)

I have no control over the colours

This is the display https://www.epson.co.uk/products/sd/pos ... 110-series

It is a rs232 device
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Text progress bar

Post by D.J.Peters »

Code: Select all

const as integer MAX_ROWS  =  4
const as integer MAX_CHARS = 20

sub updateProgress(title as string,curSize as integer, maxSize as integer, atRow as integer=2)
  static var old=0
  var nChars=0
  if maxSize<1 then return
  if curSize<0 then curSize=0
  if curSize>maxSize then curSize=maxSize
  nChars = curSize*(MAX_CHARS-1)/maxSize   
  locate atRow,1,0 : print string(MAX_CHARS, 32) 
  locate atRow,2,0 : print title
  if nChars=0 then
    locate atRow+1,0,0 : print string(MAX_CHARS-1,176)
	return
  endif	
  if old<>nChars then
    locate atRow+1,0,0 : print string(MAX_CHARS-1,176)
    locate atRow+1,0,0 : print string(nChars,219)
	old=nChars
  endif
  if curSize>=maxSize then old=0  
end sub

Width MAX_CHARS,MAX_ROWS

' simulate some downloads
data 3 ' # files
data "Catalog.db"   ,1024*512    ' 0.5MB
data "FB-Manual.chm",1024*1024   ' 1MB
data "FreeBASIC.zip",1024*1024*5 ' 5MB


var nFiles=0,i=0,file="",size=0,bytes=0
read nFiles
for i = 1 to nFiles 
  read file,size : bytes=0
  while bytes<size
    bytes+=16*1024 + 16*1024*rnd
	updateProgress(file,bytes,size)
	sleep 100
  wend
next  

sleep
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Post by Gablea »

Thank you.

So all I need to do is replace the existing progress bar update sub function to the new one?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Text progress bar

Post by MrSwiss »

Gablea wrote:So all I need to do is replace the existing progress bar update sub function to the new one?
Unfortunately no. Because my check, with 2 x 20 settings shows, it's not working correctly.
- flickering
- title overwritten by progress-bar
...

I've adapted the code (mainly the Sub), which now seems OK:

Code: Select all

' Sub_updateProgress.bas -- original by D.J.PETERS (Joshy)
' recoded (for smaller display) -- by MrSwiss
'
' compile: -s console
'
Const MAX_ROWS = 2, MAX_CHARS = 20          ' display size

sub updateProgress( _                       ' all internal line-feed's suppressed!
    ByVal title   As String, _              ' file name (in this case)
    ByVal curSize As ULong, _               ' current size (in byte)
    ByVal maxSize As ULong, _               ' maximum size (in byte)
    ByVal atRow   As UShort = 1 _           ' default: start row = 1
    )
    Static Var old = 0                      ' local var's
    Var nChars = 0

    If maxSize < 1 Then Exit Sub            ' err check --> quit (if = 0)
    If curSize > maxSize Then curSize = maxSize ' correction (if needed)

    Locate(atRow, 2, 0) : Print title;      ' switch cursor OFF + show title
    nChars = curSize*(MAX_CHARS-1)/maxSize  ' bar current size calc.

    If nChars = 0 Then                      ' on start and, incr. < 1 step size
        Locate(atRow+1, 1) : Print String(MAX_CHARS-1, 176);    ' BG only
        Exit Sub                            ' done, quit Sub
    End If  
    If old <> nChars Then                   ' display bar's advancement (if any)
        Locate(atRow+1, 1) : Print String(MAX_CHARS-1, 176);    ' show BG
        Locate(atRow+1, 1) : Print String(nChars, 219);         ' show bar
        old = nChars                        ' save current end pos.
    End If
    If curSize >= maxSize Then old = 0      ' reset end pos. (if finished)
end sub


' start demo code
Width MAX_CHARS, MAX_ROWS
' simulate some downloads
data 3                                      ' # files
data "Catalog.db"   , 1024 * 512            ' 0.5 MB
data "FB-Manual.chm", 1024 * 1024           ' 1 MB
data "FreeBASIC.zip", 1024 * 1024 * 5       ' 5 MB

var nFiles=0,i=0,file="",size=0,bytes=0
read nFiles
for i = 1 to nFiles
  read file,size : bytes=0
  while bytes<size
    bytes+=16*1024 + 16*1024*rnd
    updateProgress(file,bytes,size)
    Sleep 100, 1
  wend
Next
' added "done" MSG (following line, taken out of Sub! caused flickering!)
Locate(2, 1) : print string(MAX_CHARS, 32); ' overwrite bar (with spaces)
Locate(2, 2, 1) : Print "done ... ";        ' switch cursor ON again + MSG

Sleep
For details, check comments, in code.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Post by Gablea »

Thank you guys you are the best.

Getting the software to work with the small screen is going to be simpler then the bigger screens :)

The problems I can see with this app is making it run smooth in DOS (as that is the OS I’ve selected for the till) and the mutisaver options (still working on the windows version using vb.net)

I’m open to any ideas or suggestions on how to process the mutlisavers
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Text progress bar

Post by MrSwiss »

Getting the software to work with the small screen is going to be simpler then the bigger screens :)
Nope, in this case, it was exactly the opposite ...

No idea, what you are referring to: *multisavers* (FB-code?)
I don't know the first thing about: VB.NET ... (anyway: you stated DOS!)

Could you plse. be a bit more detailed (and, less confusing)?
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Post by Gablea »

Sorry
What I mean is I’m writing a cash register software to run on the smaller screens and as I do not have to keep resfrshing the display I think that I should be easier to make

The mutlisavers are part of the till software for example

Buy one coke get one free
But 6 bottles of wine and get 10% off all 6

Buy a sandwich and a drink and a pack at crips and get it all for £3.50 (meal deal)

Because I have a vb.net version of the till software all ready running in Windows I’m also trying to add the same promotion support to that version as well (if I can figure them out on the FreeBASIC / DOS version it should not be that hard to migrate the code base of the promotions to the .net version)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Text progress bar

Post by MrSwiss »

Well, I'd open a different thread, for this *'multisaver* issue.

I don't see the connection, to this threads title ...
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Post by Gablea »

Ok I’ll do that.

Thanks for the code to do the small display :) I’ll be testing that tomorrow when I’m back at the office.
Post Reply