It is currently Wed Nov 25, 2020 3:14 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Done] #PB_Any example not working
PostPosted: Thu Oct 29, 2020 10:01 pm 
Offline
User
User

Joined: Thu Oct 22, 2020 7:01 am
Posts: 16
Hello im a bit new so i dont know if this is a bug or there is anything im missing but im learning purebasic following the main reference and im stuck in this example

https://www.purebasic.com/documentation ... files.html

I copy paste the code of that example and it says

ERROR LINE 25
ERROR The spefied #file is not initialised

Im using Purebasic last version on a Mac

Maybe there is a bug with the PB_ANy ? cause i was doing other example

The following code works
Code:
MessageRequester("PureBasic","Beinvenido !"+Chr(13)+"Purebasic va a escribir un archivo llamado Purebasictest.pb",0)

If CreateFile(0,"Purebasictest.txt")
  WriteStringN(0,"  Test de purebasic")
  WriteString(0,"Esto esta ")
  WriteString(0,"En la misma linea")
 
  CloseFile(0)
Else
  MessageRequester("Purebasic","Se detecto un problema escriviendo el archivo",0)
EndIf

If ReadFile(0,"Purebasictest.txt")
  First$ = Trim(ReadString(0))
  Segundo$ = Trim(ReadString(0))
  MessageRequester("Purebasic","Line read: "+First$,0)
  MessageRequester("Purebasic","Line read: "+Segundo$,0)
  CloseFile(0)
 
Else
  MessageRequester("Purebasic","Se ha detectado un problema leyendo el archivo",0)
EndIf


but if I made the changes trying to use the PB_Any with the following code..

Code:
MessageRequester("PureBasic","Beinvenido !"+Chr(13)+"Purebasic va a escribir un archivo llamado Purebasictest.pb",0)

Define.f File

File = CreateFile(#PB_Any,"Purebasictest.txt")

If File
  WriteStringN(File,"  Test de purebasic")
  WriteString(File,"Esto esta ")
  WriteString(File,"En la misma linea")
 
  CloseFile(File)
Else
  MessageRequester("Purebasic","Se detecto un problema escriviendo el archivo",0)
EndIf

File = ReadFile(#PB_Any,"Purebasictest.txt")

If File
  First$ = Trim(ReadString(File))
  Segundo$ = Trim(ReadString(File))
  MessageRequester("Purebasic","Line read: "+First$,0)
  MessageRequester("Purebasic","Line read: "+Segundo$,0)
  CloseFile(File)
 
Else
  MessageRequester("Purebasic","Se ha detectado un problema leyendo el archivo",0)
EndIf


Again i got the same error as before, file is not initialised

(sorry for the spanish in the examples)


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Thu Oct 29, 2020 10:32 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 24, 2006 3:29 am
Posts: 263
Location: Edinburgh, Scotland.
You define file as a float... which is not really necessary, just use .i or .l... however this is not the problem I suspect as the second example works fine on my machine (Win7Pro/PB 5.72)... There could be some permissions problem with with the Mac, on creating files or something like that in some directory... I have no Mac knowledge...

Anyway, most any function in PB returns a long (unless its clearly about floating point), so at least change that in your #PB_Any version and see if it miraculously makes a difference... :)

_________________
Proud supporter of PB! * Musician * C64/6502 Freak


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Thu Oct 29, 2020 10:56 pm 
Offline
User
User

Joined: Thu Oct 22, 2020 7:01 am
Posts: 16
Ah yes, sorry about that, i placed a float just to try to see if i was able to fix it. About the folder permission, i dont think so, as the second example, the one that I place 0 as the file id works well, but if I use the pb_any doesnt work

edit: I just tried it on the 5.73 beta 2 and the error happens there too

edit2: I just test it on windows machine and it works,so it looks its a Mac bug, should I create a new post in the mac bug forum ??


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Fri Oct 30, 2020 9:56 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2730
Location: Germany
Use always Integer for dynamics IDs, Handles and Pointer (Or *Pointer for Pointers). Not Long!!!

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Fri Oct 30, 2020 10:01 pm 
Offline
User
User

Joined: Thu Oct 22, 2020 7:01 am
Posts: 16
mk-soft using integer makes the example work on Mac :D

So, is this a bug or is it a documentation error? im saying this cause in the documentation they use longs
https://www.purebasic.com/documentation ... files.html


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Fri Oct 30, 2020 10:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 24, 2006 3:29 am
Posts: 263
Location: Edinburgh, Scotland.
mk-soft wrote:
Use always Integer for dynamics IDs, Handles and Pointer (Or *Pointer for Pointers). Not Long!!!


My very bad for misinformation. sorry!

This is a portability/64 bit concern tho, right as .l and .i resolve to the same 4 byte resolution under 32 bit? (I am using 32 bit compiles still)

_________________
Proud supporter of PB! * Musician * C64/6502 Freak


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Any example not working
PostPosted: Thu Nov 12, 2020 10:49 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1869
Location: Germany (Saxony, Deutscheinsiedel)
Josepho wrote:
mk-soft using integer makes the example work on Mac :D

So, is this a bug or is it a documentation error? im saying this cause in the documentation they use longs
https://www.purebasic.com/documentation ... files.html

I have changed the mentioned line 25 in the example of the linked user-guide chapter into using ".i"
Code:
  Define.i Count, File

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye