Page 1 of 1

read/write

Posted: Wed Apr 30, 2003 2:29 pm
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)

Posted: Wed Apr 30, 2003 2:55 pm
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()

Posted: Fri May 02, 2003 2:13 am
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

Posted: Sun May 04, 2003 10:57 pm
by J. Baker
anyone? fred? help?

Posted: Sun May 04, 2003 11:14 pm
by Fred
The preference lib should do it, what is wrong ?