1. Unconstant constant
- Posted by alrobnett Jan 23, 2019
- 1126 views
I want to have the user select default values which will remain (after closing the program) until he elects to change them. It would be possible to save default values in a separate file which is read upon launching the program. Is there a simpler way?
2. Re: Unconstant constant
- Posted by euphoric (admin) Jan 23, 2019
- 1140 views
I want to have the user select default values which will remain (after closing the program) until he elects to change them. It would be possible to save default values in a separate file which is read upon launching the program. Is there a simpler way?
Saving user preferences to a file (or the cloud, or whatever) is the only way to maintain those preferences from program run to program run.
3. Re: Unconstant constant
- Posted by irv Jan 23, 2019
- 1159 views
Saving to a file (often called an .ini file - from Windows usage) is the only way.
There are, of course, several ways to do this. You could simply write out the values, in a certain order, and then read them back on startup.
I find it better to use named values, so that the file can be easily examined and even modified "by hand".
For example, if I need to save settings such as current file name, x position, y position, etc. I might write out a file that looks like the following, and save it as, let's say, x.ini
filename=test1.ex x_position=123 y_position=567
To read them in, here's a snippet of code to use:
include std/io.e include std/console.e include std/text.e object input = read_file("x.ini") input = keyvalues(input) display(input)
Results:
{ { "filename", "test1.ex" }, { "x_position", "123" }, { "y_position", "567" } }
You can easily see how you can retrieve the saved values by name from this input sequence.
-- hint: include std/search.e integer x = to_number(vlookup("x_position",input,1,2))
4. Re: Unconstant constant
- Posted by ghaberek (admin) Jan 23, 2019
- 1103 views
If you're on Windows you could use the registry. Although technically that is just a really big file for a whole lot of settings.
If you're going to use a plain file (which is recommended) please play nice with the well-known locations for storing data.
On Windows it's %APPDATA%\Company\Application and on Linux it's $HOME/.config/company/application.
-Greg
5. Re: Unconstant constant
- Posted by petelomax Jan 23, 2019
- 1132 views
On phix I'd strongly recommend IupConfig
Otherwise, like that (APP_NAME option), I recommend constructing an appropriate filename from getenv("APPDATA") on windows, or getenv("HOME") on linux, rather than just plonking it in C:\Program Files, that is if you ever plan on letting anyone else install and run it, certainly on anything beyond a bog standard single-user home pc/laptop, otherwise you risk one day running into errors caused by permissions, active_directory, and/or reparse point handling (tip:don't ask).
6. Re: Unconstant constant
- Posted by alrobnett Jan 23, 2019
- 1108 views
Thanks, to all. I now have what I need.