Writing in a file

Just starting out? Need help? Post your questions and find answers here.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol. :lol:
@}--`--,-- A rose by any other name ..
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Hey Trond, what about an english translation ? :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

? Simply a way to pass only the first parameter without the compiler complaining. Of course, it doesn't do any good.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Oh... Thx :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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...
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
Last edited by netmaestro on Tue Feb 21, 2006 7:35 pm, edited 2 times in total.
BERESHEIT
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
Last edited by netmaestro on Tue Feb 21, 2006 7:37 pm, edited 2 times in total.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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









Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thank you, it works perfectly.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply