Page 1 of 1

[Solved] Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 9:44 pm
by IdeasVacuum
GetPathPart returns a string, so I expected this to work:

Code: Select all

Global sgCurrentFile.s = "C:\MyFile.txt"

Procedure SaveFileAs()
;---------------------
Static sDefaultSaveAs.s = GetPathPart(sgCurrentFile) ;Line 5: Bad parameter type: a string is expected.

         sDefaultSaveAs = SaveFileRequester("Save File As", sDefaultSaveAs, "*.txt|*.txt|*.*|*.*", 0)
                           MessageRequester("Save File As", sDefaultSaveAs + " Saved", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)
EndProcedure

SaveFileAs()
If 'Static' is replaced by 'Protected', it does work.......
The reason for the failure is not "Bad parameter type: a string is expected.", it is "Only literal expressions are valid for 'Static'"

Isn't that a shame though? I just want to initialise the static var with the currently active file for the first time SaveAs is called, so the file browser will open the folder most likely to be used.

Re: Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 10:02 pm
by skywalk
Works if 2 separate lines...
Static sDefaultSaveAs.s
sDefaultSaveAs = GetPathPart(sgCurrentFile)

Re: Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 10:03 pm
by Bisonte

Code: Select all

Static sDefaultSaveAs.s = GetPathPart(sgCurrentFile)
This can't work....

Imagine : Every time you call the procedure, you set the "STATIC" var to a default ;) So it's like "Protected"

Re: Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 10:11 pm
by BorisTheOld
IdeasVacuum wrote:

Code: Select all

Static sDefaultSaveAs.s = "xxxxxxxxxxxxxxx"
The above syntax can only be used to assign a constant value at compile time.

Re: Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 10:29 pm
by IdeasVacuum
Imagine : Every time you call the procedure, you set the "STATIC" var to a default ;) So it's like "Protected"
Yeah, I was thinking the Static line is ignored after initialisation, but as Skywalk has pointed out with his example, my thoughts were gibberish! :D

Re: [Solved] Bad parameter type: a string is expected

Posted: Sat Aug 16, 2014 11:19 pm
by luis
Looking at the code you wrote you wanted to initialize the static var with the path of the ... etc.

Code: Select all

Procedure SaveFileAs()
 Static sDefaultSaveAs.s

 If sDefaultSaveAs = ""
    sDefaultSaveAs = GetPathPart(sgCurrentFile) 
 EndIf

 sDefaultSaveAs = SaveFileRequester("Save File As", sDefaultSaveAs, "*.txt|*.txt|*.*|*.*", 0) 
 MessageRequester("Save File As", sDefaultSaveAs + " Saved", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)

EndProcedure
Don't know what you want to happen on subsequent calls, but this does what you asked.
IdeasVacuum wrote:I just want to initialise the static var with the currently active file for the first time SaveAs is called

Re: [Solved] Bad parameter type: a string is expected

Posted: Sun Aug 17, 2014 4:52 pm
by IdeasVacuum
Hi luis - yes, I changed the code, same as your snippet. First time SaveAs is called, the default folder is the same as the current file. For the SaveFileRequester line, next time the default folder is the folder last saved-as to. Works like a charm.