Inifile.

In this category you can exchange your programming questions and solutions.
Post Reply
Akirky
Posts: 4
Joined: Tue Nov 08, 2005 3:00 pm

Inifile.

Post: # 388Post Akirky
Mon Jan 12, 2009 7:40 am

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.


PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

Inifile.

Post: # 389Post PaPi
Mon Jan 12, 2009 3:39 pm

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

Post Reply