Page 2 of 2

Posted: Sun Jan 22, 2006 3:31 pm
by Dare2
lol. :lol:

Posted: Sun Jan 22, 2006 5:46 pm
by Inf0Byt3
Hey Trond, what about an english translation ? :)

Posted: Sun Jan 22, 2006 6:18 pm
by Trond
? Simply a way to pass only the first parameter without the compiler complaining. Of course, it doesn't do any good.

Posted: Sun Jan 22, 2006 7:48 pm
by Inf0Byt3
Oh... Thx :)

Posted: Fri Jan 27, 2006 11:52 pm
by Inf0Byt3
This s**t is freaking me out... :evil: I simply can't get it to work :( . I need to write to a file from a filled memory buffer and show the progress for this.
Please help me cause i'm getting nuts. It's simple but i spent 1 week trying to make it and ... no sucess...

Posted: Fri Jan 27, 2006 11:56 pm
by netmaestro
There are some examples of this on the forum. Freak has an excellent tutorial on downloading a file that shows how to do it.

Posted: Sat Jan 28, 2006 12:10 am
by Inf0Byt3
The problem is not the progressbar itself. It's showing the progress when creating the file, i mean

Code: Select all

if createfile(0,"blah.txt")
 writedata(*sdasdads,length)
 ;now show progress- but how do i know how many bytes were written?
closefile(0)

Posted: Sat Jan 28, 2006 12:51 am
by netmaestro
Oh. OK, well then what you'll do is continually interrupt your writing process to update a variable or memory bank, and start a thread that watches the memory bank and displays a progress bar gadget according to what it finds.

Posted: Sat Jan 28, 2006 10:45 am
by Trond
Example without a thread:

Code: Select all

#MemSize = 30594500

MyMem = AllocateMemory(#MemSize)
*byte.byte = MyMem
For I = 0 To #MemSize ; Fill with some readable characters
  *byte\b = (I % 100)+32
  *byte + 1
Next

OpenWindow(0, 0, 0, 400, 100, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "")
CreateGadgetList(WindowID())
  ProgressBarGadget(0, 10, 10, 300, 20, 0, 100, #PB_ProgressBar_Smooth)
  ButtonGadget(10, 10, 50, 97, 25, "Start")
  TextGadget(20, 120, 55, 100, 20, "Press start")

Procedure UpdateStatus(Percent.l)
  SetGadgetState(0, Percent)
  SetGadgetText(20, Str(Percent)+"%")
EndProcedure

Procedure WriteToFile(Pointer.l, Length.l)
  Protected I
  Protected P
  Protected O
  P = Pointer
  O = Int(Length * (I+1) / 100.0)
  For I = 0 To 99
    WriteData(P, O)
    UpdateStatus(I+1)
    P + O
  Next
  WriteData(P, Length-(P-Pointer))
  DisableGadget(10, 0)
EndProcedure

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadgetID()
        Case 10
          DisableGadget(10, 1)
          SetGadgetText(20, "0%")
          CreateFile(0, "c:\_hopethisisjunk.txt")
          WriteToFile(MyMem, #MemSize)
          CloseFile(0)
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver










Posted: Sat Jan 28, 2006 7:32 pm
by Inf0Byt3
Thank you, it works perfectly.