Page 1 of 1
[PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 8:12 am
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
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 10:48 am
by Fred
You should always use 'if' for readfile before continuing. The file can be in use or deleted etc.
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 11:29 am
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.
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 11:33 am
by Mindphazer
Why not use #PB_Any, instead of a given number ?
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 12:56 pm
by Fred
You need to post a code which show the error or we can't investigate.
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 3:41 pm
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.
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 3:42 pm
by jacdelad
Maybe a threading thing?
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 8:29 pm
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?
Re: [PB6.10beta6] File is not initialised
Posted: Thu Feb 22, 2024 8:48 pm
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.