[Solved] Bad parameter type: a string is expected

Just starting out? Need help? Post your questions and find answers here.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

[Solved] Bad parameter type: a string is expected

Post 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.
Last edited by IdeasVacuum on Sat Aug 16, 2014 10:29 pm, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Bad parameter type: a string is expected

Post by skywalk »

Works if 2 separate lines...
Static sDefaultSaveAs.s
sDefaultSaveAs = GetPathPart(sgCurrentFile)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: Bad parameter type: a string is expected

Post 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"
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Bad parameter type: a string is expected

Post 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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Bad parameter type: a string is expected

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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
"Have you tried turning it off and on again ?"
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply