If FileExists as Macro

Just starting out? Need help? Post your questions and find answers here.
Oxyandy
User
User
Posts: 10
Joined: Wed Jun 26, 2013 5:15 pm

If FileExists as Macro

Post 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
[url]irc://freenode/purebasic[/url]
User avatar
idle
Always Here
Always Here
Posts: 6109
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: If FileExists as Macro

Post 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$);   

Windows 11, Manjaro, Raspberry Pi OS
Image
Oxyandy
User
User
Posts: 10
Joined: Wed Jun 26, 2013 5:15 pm

Re: If FileExists as Macro

Post 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)
[url]irc://freenode/purebasic[/url]
Post Reply