[PB6.10beta6] File is not initialised

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

[PB6.10beta6] File is not initialised

Post by marcoagpinto »

Why does it give the error in the subject?

Code: Select all

 ; Load the .txt file
  ReadFile(5,file$)
    ReadStringFormat(5)
    t$=ReadString(5,#PB_UTF8|#PB_File_IgnoreEOL) 
  CloseFile(5)
If I use 1 as file number, it works okay.

Code: Select all

; Pre-count the number of words in .txt file to avoid using ReDim
; Quick way of counting words in a .txt files to avoid using Redim for each new entry, if it doesn't end in an #LF$, it increases in one word count
;
; V1.0 - 22/FEB/2024
;
Procedure words_missing_in_master_wordlist_import_and_process_pre_count_words_in_file(file$)
  
  Debug "file$:"+file$
  
  ; Load the .txt file
  ReadFile(5,file$)
    ReadStringFormat(5)
    t$=ReadString(5,#PB_UTF8|#PB_File_IgnoreEOL) 
  CloseFile(5)
  
  ; Convert to Unix
  ConvertStringToUnix(t$)
  
  ; Count number of words
  counter=CountString(t$,#LF$)
  If Right(t$,1)<>#LF$ : counter+1 : EndIf
  
  Debug "counter:"+Str(counter)
  
  ; Return the number of words
  ProcedureReturn counter
  
EndProcedure
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.10beta6] File is not initialised

Post by Fred »

You should always use 'if' for readfile before continuing. The file can be in use or deleted etc.
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.10beta6] File is not initialised

Post by marcoagpinto »

Fred wrote: Thu Feb 22, 2024 10:48 am You should always use 'if' for readfile before continuing. The file can be in use or deleted etc.
Fred, but if I place 1 it works, but if I place 5 or 100 it gives an error.

The maximum I use in file numbers is 1 or 2 in ALL MY SOFTWARE, so using 5 or 100 never should give any issues.
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 487
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: [PB6.10beta6] File is not initialised

Post by Mindphazer »

Why not use #PB_Any, instead of a given number ?
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.10beta6] File is not initialised

Post by Fred »

You need to post a code which show the error or we can't investigate.
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.10beta6] File is not initialised

Post by marcoagpinto »

Fred wrote: Thu Feb 22, 2024 12:56 pm You need to post a code which show the error or we can't investigate.
I tried to create simple code, but in the simple code it works.

So, maybe we can delete this post unless it happens to someone else.


Thanks and sorry.
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: [PB6.10beta6] File is not initialised

Post by jacdelad »

Maybe a threading thing?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: [PB6.10beta6] File is not initialised

Post by juergenkulow »

Code: Select all

; More Information failed ReadFile(5,file$)
file$="/tmp/Ogre.log"
For i=1 To 1000
  If 0=ReadFile(5,file$)
    Debug "file$:"+file$
    Debug FileSize(file$)
    Debug FormatDate("%hh %mm %ss %dd %ii %yyyy",GetFileDate(file$,#PB_Date_Created))
    Debug CheckFilename(file$)
    Debug Hex(GetFileAttributes(file$)) ;FFFFFFFFFFFFFFFF for Error 
    End 
  EndIf   
  rsf=ReadStringFormat(5)
  If rsf=#PB_UTF16BE Or rsf=#PB_UTF32 Or rsf=#PB_UTF32BE
    Debug File$+" ReadStringFormat:"+Str(rsf)
    End
  EndIf   
  t$=ReadString(5,#PB_UTF8|#PB_File_IgnoreEOL) 
  If Len(t$)=0 
    Debug file$+" Error ReadString"
    Debug FileSize(file$)
    End 
  EndIf 
  CloseFile(5)
Next   
One more question: Is there a CreateThread in your source file?
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.10beta6] File is not initialised

Post by marcoagpinto »

juergenkulow wrote: Thu Feb 22, 2024 8:29 pm

Code: Select all

; More Information failed ReadFile(5,file$)
file$="/tmp/Ogre.log"
For i=1 To 1000
  If 0=ReadFile(5,file$)
    Debug "file$:"+file$
    Debug FileSize(file$)
    Debug FormatDate("%hh %mm %ss %dd %ii %yyyy",GetFileDate(file$,#PB_Date_Created))
    Debug CheckFilename(file$)
    Debug Hex(GetFileAttributes(file$)) ;FFFFFFFFFFFFFFFF for Error 
    End 
  EndIf   
  rsf=ReadStringFormat(5)
  If rsf=#PB_UTF16BE Or rsf=#PB_UTF32 Or rsf=#PB_UTF32BE
    Debug File$+" ReadStringFormat:"+Str(rsf)
    End
  EndIf   
  t$=ReadString(5,#PB_UTF8|#PB_File_IgnoreEOL) 
  If Len(t$)=0 
    Debug file$+" Error ReadString"
    Debug FileSize(file$)
    End 
  EndIf 
  CloseFile(5)
Next   
One more question: Is there a CreateThread in your source file?


Heya,

Thanks for the code, here is the log:

Code: Select all

file$:C:\Users\marco\Desktop\LT_PT_DICS\5.PTPT_90_after.txt
19884954
13 01 13 20 52 2024
0
20
For the code:

Code: Select all

  If 0=ReadFile(5,file$)
    Debug "file$:"+file$
    Debug FileSize(file$)
    Debug FormatDate("%hh %mm %ss %dd %ii %yyyy",GetFileDate(file$,#PB_Date_Created))
    Debug CheckFilename(file$)
    Debug Hex(GetFileAttributes(file$)) ;FFFFFFFFFFFFFFFF for Error 
    End 
  EndIf   
Thanks!

EDIT: I am not using threads.
Post Reply