Re: Unconstant constant
- Posted by irv Jan 23, 2019
- 1160 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))