progress bar

need help making one to show how much of a file has finished copying. don't even know were to start. hears my code for copying a file:

DIM B AS STRING * 1
OPEN "qbasic.EXE" FOR BINARY AS #1
OPEN "C:qbasic.EXE" FOR BINARY AS #2


WHILE NOT EOF(1)
GET #1, , B
PUT #2, , B

WEND
CLOSE #1
CLOSE #2
PRINT "done"

the bar must be in text format for screen 0. eg. made from a row of chr$(219)

please help. cheers

Comments

  • [b][red]This message was edited by the walrus at 2003-10-15 8:38:15[/red][/b][hr]
    : need help making one to show how much of a file has finished copying. don't even know were to start. hears my code for copying a file:

    (sorry, I didnt even test this to see how it would look as far as the progress bar and you may need to substitute [b]Seek[/b] for [b]Loc[/b]...I get those confused sometimes..but this will show you the basic concept.)

    Using your code:

    [code]
    SCREEN 12
    DIM B AS STRING * 1, CopyProgress AS SINGLE
    OPEN "d:qbasicc7inqbx.EXE" FOR BINARY AS #1
    OPEN "d:qcopy.EXE" FOR BINARY AS #2


    LINE (50, 50)-(200, 90), 7, B
    WHILE NOT EOF(1)
    GET #1, , B
    PUT #2, , B
    IF NOT LOC(1) = 0 THEN CopyProgress = (LOC(1) / LOF(1))
    LINE (50, 50)-(50 + 200 * CopyProgress , 90), 9, BF
    WEND
    CLOSE #1
    CLOSE #2
    PRINT "done"
    [/code]

    If you're going to use your code you may want to use a Byte Array or a larger String to copy the file...im not sure if QBasic supports that though.. ?

    But all of this code is going to slow down the copying of the file considerably.. I'd suggest just using

    [code]
    Shell "copy qbasic.exe c:qbasic.exe"
    [/code]








  • Here; I tested it and sped it up a LOT:

    [code]
    SCREEN 12
    DIM b AS STRING * 700, CopyProgress AS SINGLE
    OPEN "d:qbasicc7inqbx.EXE" FOR BINARY AS #1
    OPEN "d:qcopy.EXE" FOR BINARY AS #2


    LINE (50, 50)-(200, 90), 7, B
    WHILE NOT EOF(1)
    b = STRING$(700, " ")
    GET #1, , b
    PUT #2, , b
    IF NOT LOC(1) = 0 THEN CopyProgress = (LOC(1) / LOF(1))
    LINE (50, 50)-(50 + (200 - 50) * CopyProgress, 90), 9, BF
    WEND
    CLOSE #1
    CLOSE #2
    PRINT "done"
    [/code]
  • : Here; I tested it and sped it up a LOT:
    :
    : [code]
    : SCREEN 12
    : DIM b AS STRING * 700, CopyProgress AS SINGLE
    : OPEN "d:qbasicc7inqbx.EXE" FOR BINARY AS #1
    : OPEN "d:qcopy.EXE" FOR BINARY AS #2
    :
    :
    : LINE (50, 50)-(200, 90), 7, B
    : WHILE NOT EOF(1)
    : b = STRING$(700, " ")
    : GET #1, , b
    : PUT #2, , b
    : IF NOT LOC(1) = 0 THEN CopyProgress = (LOC(1) / LOF(1))
    : LINE (50, 50)-(50 + (200 - 50) * CopyProgress, 90), 9, BF
    : WEND
    : CLOSE #1
    : CLOSE #2
    : PRINT "done"
    : [/code]
    :

    One definite problem with that code: screen 0 (text only!) was requested.
    And one probably problem: that particular code should create a file that is always a multiple of 700. Should be easy enough to fix though.
  • [b][red]This message was edited by the walrus at 2003-10-20 14:15:52[/red][/b][hr]
    : One definite problem with that code: screen 0 (text only!) was requested.
    : And one probably problem: that particular code should create a file that is always a multiple of 700. Should be easy enough to fix though.
    :

    oh alright, i didnt see the request for screen 0...

    [code]
    DIM b AS STRING * 700, CopyProgress AS SINGLE, oCount as Integer
    OPEN "qbasic.EXE" FOR BINARY AS #1
    OPEN "c:qbasic.EXE" FOR BINARY AS #2


    color 9
    Locate 23
    Print String$(80, chr$(176))
    WHILE NOT EOF(1)
    b = STRING$(700, " ")
    GET #1, , b
    PUT #2, , b
    IF NOT LOC(1) = 0 THEN CopyProgress = (LOC(1) / LOF(1))
    if not oCount=Int(80 * CopyProgress) then
    oCount=Int(80 * CopyProgress)
    Locate 23: Print String$(Int(80 * CopyProgress), chr$(219))
    end if
    WEND
    CLOSE #1
    CLOSE #2
    locate 1
    color 15
    PRINT "done"
    [/code]

    i didnt think the extra spaces at the end of the file would matter, other than making the file a *little* bigger...i also figured he could work his way around it and that i didnt need to fix that for him if the slight variation in file size was a problem...


  • : i didnt think the extra spaces at the end of the file would matter, other than making the file a *little* bigger...i also figured he could work his way around it and that i didnt need to fix that for him if the slight variation in file size was a problem...
    :

    And that wasn't what was requested anyway so I didn't bother to post new code. Anyway, it'll give the asker something to do.
  • This code will be at a good speed, whithout increasing the file size too much:

    (small letters are my code)

    DIM B AS STRING * 10
    OPEN "qbasic.EXE" FOR BINARY AS #1
    OPEN "C:qbasic.EXE" FOR BINARY AS #2
    color 9,1
    n=1
    newfilesize=(lof(1)10)*10 'The future file size
    locate barrow,barcolumn
    'the line below prints the background before entering the loop
    print space$(barwidth)
    WHILE NOT EOF(1)

    GET #1, , B
    PUT #2, , B
    n=n+10
    percent=int((n/newfilesize)*100)
    locate barrow,barcolumn
    print string$(barwidth/100*percent,219);
    'print space$(100-(barwidth/100*percent))

    WEND
    CLOSE #1
    CLOSE #2
    PRINT "done"

    BarRow and BarColumn defines the coordinates of the bar in the text screen
    BarWidth defines the width of the bar, in characters
    The commented line prints the background of the bar, in the part which is not filled, but if you prints the background before entering the loop, its not needed.

    Mail Me!
    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil

  • : need help making one to show how much of a file has finished copying. don't even know were to start. hears my code for copying a file:
    :
    : DIM B AS STRING * 1
    : OPEN "qbasic.EXE" FOR BINARY AS #1
    : OPEN "C:qbasic.EXE" FOR BINARY AS #2
    :
    :
    : WHILE NOT EOF(1)
    : GET #1, , B
    : PUT #2, , B
    :
    : WEND
    : CLOSE #1
    : CLOSE #2
    : PRINT "done"
    :
    : the bar must be in text format for screen 0. eg. made from a row of chr$(219)
    :
    : please help. cheers
    :

    Static strings aren't needed. Also, for the best performance, use a string whose size is a power of 2. I'm only guessing, but I believe the disk drivers retrieve a sector at a time so the closer you get to a sector size, the better the performance. I'm not sure that, with buffering, this will give much of a boost but it can't hurt.

    [code]DIM FD AS STRING
    DIM SrcFile AS STRING, DestFile AS STRING
    DIM FFile1 AS LONG, FFile2 AS LONG
    FFile1 = FREEFILE
    OPEN SrcFile FOR BINARY AS FFile1
    FFile2 = FREEFILE
    OPEN DestFile FOR BINARY AS FFile2
    FD = SPACE$(1024)
    DO UNTIL SEEK(FFile1) + 1024 >= LOF(FFile1)
    GET FFile1, , FD
    PUT FFile2, , FD
    ' ShowProgress INT(SEEK(FFile1) LOF(FFile1) * 100)
    LOOP
    IF SEEK(FFile1) <= LOF(FFile1) THEN
    FD = SPACE$(LOF(FFile1) - SEEK(FFile1) + 1)
    GET FFile1, , FD
    PUT FFile2, , FD
    END IF
    'ShowProgress 100
    CLOSE FFile1
    CLOSE FFile2
    [/code]
    That code will generate an identical destination file. Fill in SrcFile and DestFile and run it.

    To use this code as it is, you will need to create a sub called ShowProgress that accepts one parameter, the percentage complete, and remove the comment marks from those lines. The param passed has a value between 0 and 100. I didn't bother writing that part because the others seem to have done it just fine.

    Hope this helps!
    KDL
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories