WritePreferenceString

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

This does not create the required entry in the existing "myapp.ini" file...

Code: Select all

Result = OpenPreferences(appdir$+"myapp.ini") 
If Result
  PreferenceGroup("") ; No grouping
  s$ = ReadPreferenceString("MY_ADDINS", "")
  If s$=""
    s$ = "myaddin.dll"
  Else
    s$ = "myaddin.dll,"+s$
  EndIf

  WritePreferenceString("MY_ADDINS", s$)
  ClosePreferences()
EndIf
PS: "MY_ADDINS" entry may/ may not exist. At the moment it does not.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

OpenPreference() is only for read!
And don't test, if the result is true, because then you can only open a existing file!

When you not test, you get back the default-settings.

And when you dont have a group, you don't need PreferenceGroup()!

OpenPreferences(appdir$+"myapp.ini")
s$ = ReadPreferenceString("MY_ADDINS", "")
If s$=""
s$ = "myaddin.dll"
Else
s$ = "myaddin.dll,"+s$
EndIf
closepreference()

if createpreference(appdir$+"myapp.ini")
WritePreferenceString("MY_ADDINS", s$)
ClosePreferences()
EndIf
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

Hi GPI, thanks for the info but my ini file *does* already exist. I'm just trying to change/ add one entry. I cannot use createpreference() because according to help...

"Creates a new empty preference file. If the file already exists, the file is erased"
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Than you must read complete the preference-file and write complete the reference-file!

When you want to change the meaning of one of your preference-strings you should rename it.

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
Post Reply