Hi everybody
i try to read a text file by (OpenAsTextFile) twice… but the second time xojo don’t find it
enven if i Close it at the end of my method
[code] Dim sPath as string
sPath = foldops.NativePath + “/gentab.txt”
foldops = GetFolderItem(sPath,1)
tis = foldops.OpenAsTextFile
if tis=nil then 'failed?------------ YES fail here at the second time only (tis is empty on break)
MsgBox(“Le fichier “+foldops.name+” n’est pas trouver”)
exit sub
end if
tis.Close 'close file[/code]
i guess the file still hang by xojo …but dont know how release it
thanks
[quote=83093:@Denis Despres]Hi everybody
i try to read a text file by (OpenAsTextFile) twice… but the second time xojo don’t find it
enven if i Close it at the end of my method
[code] Dim sPath as string
sPath = foldops.NativePath + “/gentab.txt”
foldops = GetFolderItem(sPath,1)
tis = foldops.OpenAsTextFile
if tis=nil then 'failed?------------ YES fail here at the second time only (tis is empty on break)
MsgBox(“Le fichier “+foldops.name+” n’est pas trouver”)
exit sub
end if
tis.Close 'close file[/code]
i guess the file still hang by xojo …but dont know how release it
thanks[/quote]
Is foldops a global ?
If so it can’t find it because the second time its looking for the wrong thing as you modify foldops
add code to check to see if folder item is not nil prior to opening.
dim foldops as folderitem, tis as textinputstream
foldops = getopenfolderitem("")
if foldops = nil then ' check to see if foldops is nil.. if not, move on.
msgbox "foldops is nil"
exit
end if
tis = textinputstream.open(foldops)
msgbox tis.readall
tis.close
@Norman Palardy : Yes foldops is global, but i don’t modify it between each reading @Rich Hatfield : Yes it return Nil, the second time only @Michel Bujardet : Thanks, even if at this stage…its really the last of my problem @Emile Schwarz : Migrate code from old version… Real studio (At home) and later Xojo (At work)
I guess its wrong syntax for newer version?
Just to summarize the solution, Norman had it right. The original code was indeed modifying foldops the first time, where it said:
Dim sPath as string
sPath = foldops.NativePath + "/gentab.txt"
foldops = GetFolderItem(sPath,1)
It was basically saying foldops=foldops+"/gentab.txt". Then the next time you came around, it added another gentab.txt to the path.
To avoid that, you could either do what I suggested:
tis = foldops.child("gentab.txt").openastextfile
Or if you needed to refer to it more than once you could set up a new folderitem, then set that to equal foldops.child(“gentab.txt”):
dim gentab as folderitem = foldops.child("gentab.txt")
tis = gentab.openastextfile
Also, you want to stick with [folderitem].Child(filename/directory) instead of setting the path manually if you can. When you switch to another operating system, you may have issues with the path separator (is it “/”, “”, “:”).