Text progress bar

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

Text progress bar

Postby Gablea » Mar 20, 2018 21:20

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: 406
Joined: Apr 30, 2015 19:28
Location: Texas,U.S., Earth,Solar System
Contact:

Re: Text progress bar

Postby Boromir » Mar 20, 2018 21:26

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: 915
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Text progress bar

Postby badidea » Mar 20, 2018 21:39

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

Re: Text progress bar

Postby Boromir » Mar 20, 2018 21:44

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: 966
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Postby Gablea » Mar 21, 2018 5:59

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-display/epson-dm-d110-series

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

Re: Text progress bar

Postby D.J.Peters » Mar 21, 2018 9:53

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: 966
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Postby Gablea » Mar 21, 2018 16:55

Thank you.

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

Re: Text progress bar

Postby MrSwiss » Mar 21, 2018 19:05

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: 966
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Postby Gablea » Mar 21, 2018 20:56

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: 2735
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Text progress bar

Postby MrSwiss » Mar 21, 2018 21:45

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: 966
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Text progress bar

Postby Gablea » Mar 21, 2018 22:21

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: 2735
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Text progress bar

Postby MrSwiss » Mar 21, 2018 22:49

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

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

Re: Text progress bar

Postby Gablea » Mar 21, 2018 22:52

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.

Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 3 guests