Page 1 of 1
assigning id to file operations
Posted: Tue Apr 30, 2024 11:15 pm
by CaptBenB
Code: Select all
testFile$ = "myTestFile"
testFileID1 = 101 ; -- as a variable
#testFileID2 = 101 ; -- as a constant
;--------------------------------------------------------
If ReadFile(0,testFile$)
Format = ReadStringFormat(0) ; -- works
;--------------------------------------------------------
If ReadFile(testFileID1, testFile$)
Format = ReadStringFormat(testFileID1) ; -- error: the specific file is not initialised
;---------------------------------------------------------
If ReadFile(#testFileID2, testFile$)
Format = ReadStringFormat(#testFileID2) ; -- error: the specific file is not initialised
I'm not understanding the issue here.
Any help is appreciated.
Thanks in advance.
Re: assigning id to file operations
Posted: Wed May 01, 2024 12:43 am
by mk-soft
Hello,
no problem here,
but your code is not complete to make a statement.
Re: assigning id to file operations
Posted: Wed May 01, 2024 7:18 am
by STARGÅTE
If you want to start reading the same file multiple times, you need #PB_File_SharedRead, otherwise the file is locked by the first ReadFile()
Re: assigning id to file operations
Posted: Wed May 01, 2024 7:39 am
by BarryG
I understand about #PB_File_SharedRead, but if that's not used then shouldn't "If ReadFile" return 0 then? And thus prevent OP's situation with ReadStringFormat?
Re: assigning id to file operations
Posted: Wed May 01, 2024 8:08 am
by STARGÅTE
BarryG wrote: Wed May 01, 2024 7:39 am
I understand about #PB_File_SharedRead, but if that's not used then shouldn't "If ReadFile" return 0 then? And thus prevent OP's situation with ReadStringFormat?
Yes, but CaptBenB's code was anyway not executable. So my answer was more general.
Re: assigning id to file operations
Posted: Wed May 01, 2024 9:44 am
by spikey
STARGÅTE wrote: Wed May 01, 2024 7:18 am
If you want to start reading the same file multiple times, you need #PB_File_SharedRead, otherwise the file is locked by the first ReadFile()
Or you need to close the file before attempting to re-open. This works:
Code: Select all
testFile$ = "myTestFile"
testFileID1 = 101 ; -- as a variable
#testFileID2 = 101 ; -- as a constant
;--------------------------------------------------------
If ReadFile(0,testFile$)
Format = ReadStringFormat(0)
CloseFile(0)
EndIf
;--------------------------------------------------------
If ReadFile(testFileID1, testFile$)
Format = ReadStringFormat(testFileID1)
CloseFile(testFileID1)
EndIf
;---------------------------------------------------------
If ReadFile(#testFileID2, testFile$)
Format = ReadStringFormat(#testFileID2)
CloseFile(#testFileID2)
EndIf
Re: assigning id to file operations
Posted: Sat May 04, 2024 6:03 am
by CaptBenB
Sorry I should have been more clear in my original post.
That was three different attempts in three different routines.
I must have had a typo somewhere - it could have been a hidden character.
After I tried several more times, I was able to get the code to work using any of the three methods.
My original thought was that any of those methods should work - and ultimately they did and is why I'm suspecting that there was a hidden character somewhere in my original code preventing the proper execution.
Thanks for responding.
Re: assigning id to file operations
Posted: Sat May 04, 2024 12:15 pm
by Axolotl
Welcome to the forum.
CaptBenB wrote: Sat May 04, 2024 6:03 am
....
I must have had a typo somewhere - it could have been a hidden character.
....
It is therefore very helpful to use
Even if it is often omitted in the examples here (for the sake of simplicity).