Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Tue Nov 20, 2018 2:51 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Sep 27, 2007 8:39 am 
Offline
User avatar

Joined: Thu Jun 14, 2007 9:05 am
Posts: 98
Location: Montreal - PQ
I want to act on the fact that a file exist or not.





Code:
func screenEnabled()





    dim fnum as filedesc

    dim fname as string 'getfileinfo

    dim fsize, fspace as integer

    dim flags as fileinfo_flags

    dim strfsize as string

    dim data as string



    label CheckEncore



fnum = OpenFile("MyFile.txt", FILE_BINARY and FILE_READ)





        SetFilePos(fnum, -1, true)

        fsize = GetFilePos(fnum)

        SetFilePos(fnum, 0, true)

        redim(data, fsize)

        ReadFile(fnum, data)



        strfsize= Str(fsize)



   GetFileInfo("MyFile.txt", fsize, fspace, flags)



        If fsize > 100 then




Now I can only tell if its empty or not, but not if t exist.



I'm looking for something like



Code:
If Dir("C:\MyFile.txt") <> "" Then ....

_________________
If it looks like a Cat ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 8:45 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Try

Code:
func DoesFileExist(name as string) returns boolean

    dim size as integer

    dim usedSpace as integer

    dim flags as fileinfo_flags

    check error

        GetFileInfo(name, size, usedSpace, flags)

        return true

    on error

        _ClearException()

        return false

    enderr

endfunc





Actually I think your example code could be modified to do the same thing:



Add the FILE_NO_CREATE flag when you open the file and it will throw an exception if the file does not exist.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 10:22 am 
Offline
User avatar

Joined: Thu Jun 14, 2007 9:05 am
Posts: 98
Location: Montreal - PQ
Code:
func screenEnabled()





    dim fnum as filedesc

    dim fname as string 'getfileinfo

    dim fsize, fspace as integer

    dim flags as fileinfo_flags

    dim strfsize as string

    dim data as string

    dim size as integer

    dim usedSpace as integer



fnum = OpenFile("myfile.txt", FILE_BINARY and FILE_READ and FILE_NO_CREATE)



check error

        GetFileInfo("myfile.txt", size, usedSpace, flags)

        return true



        SetFilePos(fnum, -1, true)

        fsize = GetFilePos(fnum)

        SetFilePos(fnum, 0, true)

        redim(data, fsize)

        ReadFile(fnum, data)



        strfsize= Str(fsize)



        PlayNote (10, 200)



        rem Ligne 1



        STR010.value = mid(data, 0, 25)

``more code if file exist here








Code:

    on error

        _ClearException()

        return false









                PlayNote (50, 500)

' more code if file don't exist here






I'm almost there but getting these errors:

Quote:

Error Screen1 line 25: Function call error This function is unable to return a value

Error Screen1 line 170: Function call error This function is unable to return a value

_________________
If it looks like a Cat ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 10:25 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
My example was meant as a standalone global function that you call which returns True or False depending on whether the file exists.



Paste my function into your global code and call it and it should give you what you want.



My later comment was to indicate that you could omit the function and do the test yourself as follows:



Code:
func screenEnabled()





    dim fnum as filedesc

    dim fname as string 'getfileinfo

    dim fsize, fspace as integer

    dim flags as fileinfo_flags

    dim strfsize as string

    dim data as string



    label CheckEncore



check error

    fnum = OpenFile("MyFile.txt", FILE_BINARY and FILE_READ and FILE_NO_CREATE)

on error

    _ClearException()

   ' do the file not exist code here

   return

enderr



'File exists if we got here

        SetFilePos(fnum, -1, true)

        fsize = GetFilePos(fnum)

        SetFilePos(fnum, 0, true)

        redim(data, fsize)

        ReadFile(fnum, data)



        strfsize= Str(fsize)



   GetFileInfo("MyFile.txt", fsize, fspace, flags)



        If fsize > 100 then

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group