Choices$Write
Norman Lawrence (3005) 172 posts |
I have developed a simple Wimp application using Dr Wimp as an introduction to programming in RISC OS. In the style guide it recommends the use of Choices$Write and Choices$Path but I am not clear on how to use them. Has anyone got a simple piece of code showing how to use these system variables in Basic to save and load user choices? many thanks |
Chris (121) 472 posts |
Here are the routines I used for Chars. There are only two choices to save: REM Read user choices from script in Choices LOCAL file%,obj%,value$,command$ SYS "XOS_File",17,"Choices:Chars.Choices" TO obj% IF obj%=1 THEN file%=OPENIN "Choices:Chars.Choices" WHILE NOT EOF#file% command$=GET$#file% IF INSTR(command$,":") THEN value$=RIGHT$(command$,LEN(command$)-INSTR(command$,":")) command$=LEFT$(command$,INSTR(command$,":")-1) CASE command$ OF WHEN "DesktopFont": IF value$="Yes" THEN Option_DesktopFont%=TRUE IF value$="No" THEN Option_DesktopFont%=FALSE WHEN "Open": IF value$="Yes" THEN Option_Open%=TRUE IF value$="No" THEN Option_Open%=FALSE ENDCASE ENDIF ENDWHILE CLOSE#file% ENDIF Option_Open%=FNwimp_getselect(ChoiceWin%,4) Option_DesktopFont%=FNwimp_getselect(ChoiceWin%,3) SYS "XOS_File",8,"<Choices$Write>.Chars" file%=OPENOUT "<Choices$Write>.Chars.Choices" BPUT#file%,"| Choices file for Chars" BPUT#file%,"" IF Option_Open% THEN val$="Yes" ELSE val$="No" BPUT#file%,"Open:"+val$ IF Option_DesktopFont% THEN val$="Yes" ELSE val$="No" BPUT#file%,"DesktopFont:"+val$ CLOSE#file% |
Andrew Rawnsley (492) 1445 posts |
To clarify, Choices$Path (aka Choices:) can point to more than one location. This is fine for reading – it’ll look in each location mentioned – (hence it is used for OPENIN in Chris’ example above) but not for writing (you can only write to a single location). As such, for reading you use Choices:Folder.filename whereas for writing you use <Choices$Write>.Folder.filename (note that “Folder.” in those examples is not strictly necessary, but most applications create a folder to store their data, or even a group (eg. WWW.appname.filename). Remember that if you don’t plan ahead and start by creating a folder, you can’t subsequently create a folder in a later version with the same name, as you can’t overwrite a file with a folder (although you could check for the file, read it, delete it, and create a folder). So, if you think you might ever need more than one file, make a folder. On OS5, Choices$Path and Choices$Write will likely be the same thing (path will have a dot on the end, to make it a path), but on 4.39-6 versions of the OS, Choices$Path will have a number of folders mentioned, to allow for hardware profiles and user-specific choices. Hope this clarifies things. |
Norman Lawrence (3005) 172 posts |
@Chris Big thanks for the speedy reply. Your example is exactly what I was looking for. Also thanks for the link to the source code. A great example of coding practice. I like the idea of upper case first letter for global variables and entirely lower case for local variables and will be using that naming convention in future. @ Andrew Thanks for the clarification and caution about need to think ahead with folder or filename, it was very helpful in completing my understanding in the use of Choices. Once again many thanks for the prompt help |