Page 1 of 1

Inifile.

Posted: Mon Jan 12, 2009 7:40 am
by Akirky
Hi,
I have been experimenting for the sake of learning, but i cannot seem to get an inifile to work.

The help notes notes give the following:


Methods:
DeleteKey(?section key?) ? ? ? ? ? ? ? ? ? ? ? ? ?Removes a value and the key from the inifile.
Erase(?section?) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? A group removal from the inifile.
Open(filename) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Opens or produce a new inifile.
ReadStr(?section key?) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Returns a STRING of the value, which is appropriate to the key.
WriteStr(?section key value?) ? ? ? ? ? ? ? ? ? Writes a value to the inifile.

However, when i try using any of the instructions i get build errors.
I found mention of "Special" subs/ functions, example READINI - Declare Sub Readini then add in CODE Sub READINI(). ?With my limited knowledge i cannot seem to get a working file.

Doe anyone have a working example for me to look at.
Regards,
Alan.


Inifile.

Posted: Mon Jan 12, 2009 3:39 pm
by PaPi
Hi Akirky,
this program WORK, and it have four different methods for work with ini file.
regards
PaPi

THE PROGRAM:

ini_test  by PaPi 2007
dim ifile as inifile
dim answer as string
dim fname as string
fname="ini-test.ini"
dim s as string

`method null:
ifile.open(fname)
if fileexists(fname)=false then  `not exists ini file
     ifile.writestr("first est1first_test1")
     ifile.writestr("first est2first_test2")
     ifile.writestr("second est3second_test3")
     ifile.writestr("second est4second_test4")
end if
s="method null : "+ifile.readstr("second est3")
showmessage s

`method one:
inisub(fname,answer)
s="method one: "+answer
showmessage s

`method two:
answer=inifunc(fname)
s="method two: "+answer
showmessage s

`method three:
answer=inifunc2(fname,"second est4")
s="method three: "+answer
showmessage s

`------------------------------------------------------

sub inisub(inifile_name as string, answ as string)
ifile.open(inifile_name)
if fileexists(inifile_name)=false then
     ifile.writestr("first est1first_test1")
     ifile.writestr("first est2first_test2")
     ifile.writestr("second est3second_test3")
     ifile.writestr("second est4second_test4")
end if
answ=ifile.readstr("second est3")
end sub

`------------------------------------------------------

function inifunc(inifile_name as string) as string
ifile.open(inifile_name)
if fileexists(inifile_name)=false then
     ifile.writestr("first est1first_test1")
     ifile.writestr("first est2first_test2")
     ifile.writestr("second est3second_test3")
     ifile.writestr("second est4second_test4")
end if
result=ifile.readstr("second est4")
end function


`------------------------------------------------------
function inifunc2(inifile_name as string,iniTag as string) as string
ifile.open(inifile_name)
if fileexists(inifile_name)=false then
     ifile.writestr("first est1first_test1")
     ifile.writestr("first est2first_test2")
     ifile.writestr("second est3second_test3")
     ifile.writestr("second est4second_test4")
end if
result=ifile.readstr(initag)
end function