Page 1 of 1

If FileExists as Macro

Posted: Mon Jul 01, 2013 6:33 am
by Oxyandy
I am using a request if a file exists / not exists many times in my main loop,
so I thought a Macro might be the best way to got about it, to reduce code.
(Output being 0= No, 1=Yes, 2=Error)

I am missing something and have myself stuck in an endless (for "why wont this work" loop)

FileExists(Filename$); <what I expected would work

Code: Select all

Filename$="latest.pb"

  result=FileSize(Filename$)
  Select result
    Case -1
      Debug Filename$ +" not found"
    Case -2
      Debug Filename$ +" Is a directory"
    Default
      Debug Filename$ +" is " +result + " Bytes."
EndSelect

; This works fine
What am I over looking here ?

Code: Select all

Filename$="latest.pb"

Macro FileExists
  
  result=FileSize(Filename$)
  Select result
    Case -1
      Debug Filename$ +" not found"
    Case -2
      Debug Filename$ +" Is a directory"
    Default
      Debug Filename$ +" is " +result + " Bytes."
EndSelect
EndMacro

FileExists(Filename$);	
	
;Not working ERROR see screenshots below
Image

Image

Re: If FileExists as Macro

Posted: Mon Jul 01, 2013 6:39 am
by idle
you were missing a parameter to the macro

Code: Select all

Filename$="latest.pb"

Macro FileExists(file)  :<--- here 
  
  result=FileSize(File)
  Select result
    Case -1
      Debug Filename$ +" not found"
    Case -2
      Debug Filename$ +" Is a directory"
    Default
      Debug Filename$ +" is " +result + " Bytes."
EndSelect
EndMacro

FileExists(Filename$);   


Re: If FileExists as Macro

Posted: Mon Jul 01, 2013 6:56 am
by Oxyandy
Thank you very much Idle !
That steered me in the right direction !
But I had to drop the $ between my examples like this
Now I can move forward, wasted too much time on this haha

Code: Select all

Filename$="latest.pb"

Macro FileExists(Filename)
  
  result=FileSize(Filename)
  Select result
    Case -1
      Debug Filename +" not found"
    Case -2
      Debug Filename +" Is a directory"
    Default
      Debug Filename +" is " +result + " Bytes."
EndSelect
EndMacro

FileExists(Filename$);
	
	
;(100% working finally)