No file read / write - a bug ??

Mac OSX specific forum
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

No file read / write - a bug ??

Post by michel51 »

Hello,
if I run the following code, the file "Daten.txt" I never find on my HD. The Code works as long as purebasic runs respective until you restart the Mac. It seems, that the "save"-function only writes into a "tempfile".
To read another known file is impossible.

Code: Select all

;Variablen definieren
Dim text$(100):Global anzahl

;Fenster und Gadget-Liste
If OpenWindow(0,100,100,400,520,#PB_Window_SystemMenu,"Daten laden/speichern")
  If CreateGadgetList(WindowID())
    ButtonGadget(1,20,20,100,20,"Laden")
    ButtonGadget(2,140,20,100,20,"Speichern")
    ButtonGadget(3,260,20,100,20,"Löschen")
    ListViewGadget(4,20,60,360,380)
    ButtonGadget(5,20,460,170,20,"Ein Element hinzufügen")
    ButtonGadget(6,200,460,180,20,"Letztes Element löschen")
  EndIf
Else
  MessageRequester("","Fenster konnte nicht geöffnet werden!",0)
EndIf

;StatusBar öffnen
If CreateStatusBar(0,WindowID())
  AddStatusBarField(500)
EndIf

;Laden
Procedure Laden()
If ReadFile(1,"Daten.txt")
  anzahl=Val(ReadString())
  For a=0 To anzahl
    text$(a)=ReadString()
    AddGadgetItem(4,-1,text$(a))
  Next
CloseFile(1)
StatusBarText(0,0,"Daten erfolgreich geladen "+FormatDate("%hh:%ii:%ss", Date()),#PB_StatusBar_Center )
EndIf
EndProcedure

;Speichern
Procedure Speichern()
If OpenFile(1,"Daten.txt")
  WriteStringN(Str(anzahl))
  For a=0 To anzahl
    WriteStringN(text$(a))
  Next
CloseFile(1)
StatusBarText(0,0,"Daten erfolgreich gespeichert "+FormatDate("%hh:%ii:%ss", Date()),#PB_StatusBar_Center )
EndIf
EndProcedure

;Zum eigentlichen Programmstart: Laden aufrufen
Laden()

;Das erste Element der Liste aktivieren
SetGadgetState(4,0)


Repeat
  EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_Gadget
      
      ;Schalter LADEN
      If EventGadgetID()=1
        ClearGadgetItemList(4):Laden()
      EndIf
      
      ;Schalter SPEICHERN
      If EventGadgetID()=2
        Speichern()
      EndIf      
      
      ;Schalter LISTE LÖSCHEN
      If EventGadgetID()=3
        ClearGadgetItemList(4)
        StatusBarText(0,0,"Liste gelöscht "+FormatDate("%hh:%ii:%ss", Date()),#PB_StatusBar_Center )
      EndIf
      
      ;Schalter NEUER EINTRAG
      If EventGadgetID()=5
        anzahl=anzahl+1
        text$(anzahl)="Neuer Eintrag "+FormatDate("%hh:%ii:%ss", Date())
        AddGadgetItem(4,anzahl,text$(anzahl))
      EndIf
      
      ;Schalter LETZTEN EINTRAG LÖSCHEN
      If EventGadgetID()=6
      If anzahl>=0
        RemoveGadgetItem(4,anzahl)
        anzahl=anzahl-1
      EndIf
      EndIf
             
     EndIf

Until EventID = #PB_EventCloseWindow   

End 
Sorry, but this is a file from the archiv. The comments are in german.

But what is wrong? Or is this a bug in the actual Mac-version?
Hope, anyone can help.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Post by LESTROSO »

:cry: may be a bug of mac version 3.94d...........we are waiting for a stable release.....4.00 version........


.......... :cry:
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

LESTROSO wrote::cry: may be a bug of mac version 3.94d...........we are waiting for a stable release.....4.00 version........


.......... :cry:
Thanks, I think so too :!:
But is there a solution? I need file handling! Fred, can you help?

So continuing let's wait......and hope..... :wink:
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

PB4 for OS X

Post by USCode »

I agree -- even though I primarily use the Windows version of PB, I have occasion to use the Mac OS X version but find it unstable and frequently get crashes when compiling.

I believe the PB4 version will be more stable and full-featured and if so, it could be a breakthrough product for Fred as the Mac community is 'used' to paying for software! :wink:
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Read/Write

Post by SEO »

Hi,
It is long time ago I used PB, But I think I have tested to Read Lines from an file, but I noticed that the LineEndings that worked was Unix/Linux ...

So check if you could read line by line and use Unix/Linux Line vreaks..

Only an tip.

Sven E
Post Reply