read/write

Just starting out? Need help? Post your questions and find answers here.
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

read/write

Post by J. Baker »

i was wondering how to save typed information in text fields to in ini file and load them back to proper space on load. i tried working with the save ini code snippet but couldn't figure it out.

Code: Select all

Procedure.s readINI(section.s,key.s,empty.s,inifile.s)
  result.s=Space(255)
  GetPrivateProfileString_(section,key,empty,@result,255,inifile)
  ProcedureReturn result
EndProcedure

Procedure.l writeINI(section.s,key.s,value.s,inifile.s)
  result=WritePrivateProfileString_(section,key,value,inifile)
  ProcedureReturn result
EndProcedure




If writeINI("data","again","test","C:\temp\testini.ini")
  MessageRequester("Done","Value was written to INI file",0)
  Else
  MessageRequester("Error","Could not write to INI file",#MB_ICONERROR)
EndIf

ini$=readINI("data","again","xxx","C:\temp\testini.ini")
MessageRequester("","Value returned was: "+ini$,0)
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Take a look at the preference lib in PureBasic....its easy to use.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Preference example file
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

If CreatePreferences("Preferences.prefs")
  PreferenceGroup("Global")
    WritePreferenceString("ApplicationName", "MP3 Player")
    WritePreferenceString("Version", "1.1b")

  PreferenceComment(" This is the Window dimension")
  PreferenceComment("")

  PreferenceGroup("Window")
    WritePreferenceLong ("WindowX", 123)
    WritePreferenceLong ("WindowY", 124)
    WritePreferenceFloat("WindowZ", -125.5)

  ClosePreferences()
EndIf


OpenPreferences("Preferences.prefs")

  PreferenceGroup("Window")
    Debug ReadPreferenceLong ("WindowX", 0)
    Debug ReadPreferenceLong ("WindowY", 0)
    Debug ReadPreferenceFloat("WindowZ", 0)
    
  PreferenceGroup("Global")
    Debug ReadPreferenceString("ApplicationName", "")
    Debug ReadPreferenceString("Version", "")
    
ClosePreferences()
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

this don't seem to work for what i need it for. anyone else know. i need to be able to save the text i type in my program and when i use the program again, need to open what i saved. i have three different text fields if that helps any. thanks :D
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

anyone? fred? help?
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The preference lib should do it, what is wrong ?
Post Reply