[Done] #PB_Any example not working

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

Josepho
User
User
Posts: 33
Joined: Thu Oct 22, 2020 7:01 am

[Done] #PB_Any example not working

Post by Josepho »

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: Select all

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: Select all

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)
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 274
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: #PB_Any example not working

Post by oreopa »

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
Josepho
User
User
Posts: 33
Joined: Thu Oct 22, 2020 7:01 am

Re: #PB_Any example not working

Post by Josepho »

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 ??
User avatar
mk-soft
Addict
Addict
Posts: 2977
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: #PB_Any example not working

Post by mk-soft »

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
Josepho
User
User
Posts: 33
Joined: Thu Oct 22, 2020 7:01 am

Re: #PB_Any example not working

Post by Josepho »

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
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 274
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: #PB_Any example not working

Post by oreopa »

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
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 1876
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: #PB_Any example not working

Post by Andre »

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: Select all

  Define.i Count, File
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply