Save variable to the program

Just starting out? Need help? Post your questions and find answers here.
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

Save variable to the program

Post by donSHAYA »

Hi all

If I have a variable that I want to save in the program, how do I do that? I tried:

Code: Select all

Global Start.i, Var.i

Restore Save
Read.i Start

Start + 1

Var = Start

DataSection
Save:
Data.i Var
EndDataSection
Thank you
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Save variable to the program

Post by ts-soft »

Code: Select all

Global Start.i, Var.i

PokeI(?Save, 4711)
Restore Save
Read.i Start

Debug Start

DataSection
  Save:
  Data.i 0
EndDataSection 
:lol:
only joking
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Save variable to the program

Post by Kaeru Gaman »

a preference file or a registry value would be the correct approach.
oh... and have a nice day.
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

Re: Save variable to the program

Post by donSHAYA »

I tried the PokeI() but when I close the program and open it again, it doesnt remember the value of the variable var when I closed the program last time.

I wanna do it without any files.

Thank you for the replies though.
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Save variable to the program

Post by Demivec »

donSHAYA wrote:I tried the PokeI() but when I close the program and open it again, it doesnt remember the value of the variable var when I closed the program last time.

I wanna do it without any files.
You would have to modify the original file on disk to change the values it starts with in its DataSection. Either way you are going to have to modify something on the disk. Better to leave the original alone and create a new file just for data.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Save variable to the program

Post by blueznl »

You have to create a file, and store data in there, see the help file for OpenPreferences() or check here:

http://www.xs4all.nl/~bluez/purebasic/p ... ile_system
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

Re: Save variable to the program

Post by donSHAYA »

Oh ok. Thank you
Post Reply